以下是扶苏的题解
#include <vector>
#include <array>
#include <iostream>
int n, ans;
std::vector<int> stk;
std::array<unsigned long long, 1000005> a;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n;
for (int i = 1; i <= n; ++i) {
std::cin >> a.at(i);
while (stk.size() && (a.at(i) >= a.at(stk.back()))) {
ans ^= stk.back();
stk.pop_back();
}
stk.push_back(i);
ans ^= i;
std::cout << ans << '\n';
}
}
以下是我的代码,明明代码理念是完全一致的,为什么我的过不了?
// B3666 求数列所有后缀最大值的位置.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
int n;
ull a[100000];
int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
}
stack<ull> b;
ull c=0;
for (int i = 1;i <= n;i++)
{
while (!b.empty() && a[b.top()] <= a[i])
c ^= a[b.top()], b.pop();
b.push(i);
c ^= i;
cout << c << '\n';
}
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门使用技巧:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件