제출 #1017646

#제출 시각아이디문제언어결과실행 시간메모리
1017646KindaNamelessXOR Sum (info1cup17_xorsum)C++14
100 / 100
643 ms53200 KiB
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define For(i,l,r) for(int i=l;i<=r;i++) #define ForD(i,r,l) for(int i=r;i>=l;i--) #define REP(i,l,r) For(i,l,r-1) #define PER(i,r,l) ForD(i,r-1,l) #define ff first #define ss second #define pb emplace_back #define all(x) x.begin(),x.end() #define All(x,n) x+1,x+1+n #define Alll(x,n) x,x+n #define sz(a) (signed)a.size() #ifdef NCGM #include"debug.h" #else #define debug(...) "fr"; #endif using namespace std; ll ans=0; const int N=1e6+2; int n,a[N]; pair<ll,int> t[N],t1[N],t2[N]; int cnt(int x) { int l=1,r=n; int res=0; while(l<r) { if (t[l].ff+t[r].ff<=x) { res+=(r-l); l++; } else r--; } For(i,1,n) if (t[i].ff*2<=x) res++; return res; } int cntr(int l,int r) { if (r<l) return 0; return cnt(r)-cnt(l-1); } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; For(i,1,n) cin >> a[i]; int cur=0; For(i,1,n) t[++cur]=make_pair(a[i]%2,i); sort(t+1,t+1+n); For(i,0,29) { if (i>0) { int x=0,y=0; For(j,1,n) { if ((a[t[j].ss]>>i)&1) t1[++x]=make_pair(t[j].ff+(1<<i),t[j].ss); else t2[++y]=t[j]; } For(j,1,y) t[j]=t2[j]; For(j,1,x) t[j+y]=t1[j]; } ll tmp=cntr((1LL<<i),(1LL<<(i+1))-1); tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-1); if (tmp%2) ans+=(1LL<<i); } cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

xorsum.cpp: In function 'int main()':
xorsum.cpp:63:26: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   63 |         tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-1);
      |                         ~^~
xorsum.cpp:63:46: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   63 |         tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-1);
      |                                             ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...