萌新求助,这么写为什么会有问题呢,和题解的做法本质应该是一样的啊。
但是只有 85 分,最后几个点 WA 了。
本地对拍了很久都找不到问题。
#include <bits/stdc++.h>
constexpr int N = 5000000;
char s[N + 1];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> s;
int n = std::strlen(s);
int ans = 0;
int j = 0, k = 0;
for (int i = 1; i <= n; ++i) {
if (s[i] > s[k]) {
k = j;
} else if (s[i] == s[k]) {
++k;
} else {
while (j + i - k <= i) {
j += i - k;
ans ^= j;
}
i = k = j;
}
}
std::cout << ans << '\n';
return 0;
}