이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;
typedef pair < int , int > ii;
typedef vector < int > vi;
int n, ans, a[N];
pair < int , int > b[N];
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d",&n);
for(int i = 1; i <= n; i++){
scanf("%d",a + i);
b[i] = mp(a[i]%2, i);
}
sort(b + 1, b + n + 1);
for(int k = 0; k <= 30; k++){
int say = 0;
// for(int i = 1; i <= n; i++)cout << b[i].st << " ";cout << endl;
// int x = lower_bound(b + 1, b + n + 1, mp((1<<k) - b[1].st ,0) ) - b;
// int y = lower_bound(b + 1, b + n + 1, mp((1<<(k+1) ) - b[1].st ,0) ) - b;
// int z = lower_bound(b + 1, b + n + 1, mp((1<<k) + (1<<(k+1)) - b[1].st ,0) ) - b;
// say += y - x;
// say += n - z + 1;
// int x = n + 1, y = n + 1, z = n + 1;;
for(int i = 1; i <= n; i++){
// while(x >= i + 1 and b[x - 1] >= mp((1<<k) - b[i].st ,0))x--;
// while(y >= i + 1 and b[y - 1] >= mp((1<<(k+1) ) - b[i].st ,0))y--;
// while(z >= i + 1 and b[z - 1] >= mp((1<<k) + (1<<(k+1)) - b[i].st ,0))z--;
// printf("%d %d %d -> ",x ,y ,z);
int x = lower_bound(b + 1, b + n + 1, mp((1<<k) - b[i].st ,0) ) - b;
int y = lower_bound(b + 1, b + n + 1, mp((1<<(k+1) ) - b[i].st ,0) ) - b;
int z = lower_bound(b + 1, b + n + 1, mp((1<<k) + (1<<(k+1)) - b[i].st ,0) ) - b;
say += max(y, i) - max(x, i);
say += n - max(z, i) + 1;
say = say%2;
// printf("%d %d %d\n",x ,y ,z);
}
// cout << "\nAMK\n";
vector < ii > c;
int ind = 0;
for(int i = 1; i <= n; i++){
if(a[b[i].nd ]&(1<<(k + 1)))
c.pb(mp(b[i].st + (a[b[i].nd ]&(1<<(k + 1))) , b[i].nd));
else
b[++ind] = b[i];
// b[i].st += a[b[i].nd ]&(1<<(k + 1));
}
for(int i = 0; i < c.size(); i++)
b[++ind] = c[i];
sort(b + 1, b + n + 1);
ans += (1<<k)*(say%2);
}
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.cpp: In function 'int main()':
xorsum.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < c.size(); i++)
~~^~~~~~~~~~
xorsum.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
xorsum.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",a + i);
~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |