Submission #1089828

#TimeUsernameProblemLanguageResultExecution timeMemory
1089828KasymKXORanges (eJOI19_xoranges)C++17
100 / 100
117 ms15368 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 2e5+5; int v[2][N]; struct node{ int l, r; ll sum; } seg[2][N<<2]; void build(int x, int l, int r, int id){ seg[id][x].l = l, seg[id][x].r = r; if(l == r){ seg[id][x].sum = v[id][l]; return; } int mid = (l+r)>>1; build(x<<1, l, mid, id); build(x<<1|1, mid+1, r, id); seg[id][x].sum = seg[id][x<<1].sum^seg[id][x<<1|1].sum; } void update(int x, int k, int u, int id){ if(seg[id][x].l == seg[id][x].r){ seg[id][x].sum = u; return; } int mid = (seg[id][x].l+seg[id][x].r)>>1; if(k <= mid) update(x<<1, k, u, id); else update(x<<1|1, k, u, id); seg[id][x].sum = seg[id][x<<1].sum^seg[id][x<<1|1].sum; } ll query(int x, int l, int r, int id){ if(seg[id][x].l == l and seg[id][x].r == r) return seg[id][x].sum; int mid = (seg[id][x].l+seg[id][x].r)>>1; if(r <= mid) return query(x<<1, l, r, id); else if(l > mid) return query(x<<1|1, l, r, id); else return (query(x<<1, l, mid, id)^query(x<<1|1, mid+1, r, id)); } int main(){ int n, q; scanf("%d%d", &n, &q); int pk = 0, pk1 = 0; for(int i = 1; i <= n; ++i){ int x; scanf("%d", &x); if(i&1) v[0][++pk] = x; else v[1][++pk1] = x; } // There is no updates build(1, 1, pk, 0); if(n > 1) build(1, 1, pk1, 1); // 0-tak, 1-jubut while(q--){ int op; scanf("%d", &op); if(op == 1){ int k, u; scanf("%d%d", &k, &u); if(k&1) update(1, k/2+1, u, 0); else update(1, k/2, u, 1); continue; } int l, r; scanf("%d%d", &l, &r); int wow = r-l+1; if(wow%2 == 0){ puts("0"); continue; } if(l%2 == 0){ assert(r%2 == 0); printf("%lld\n", query(1, l/2, r/2, 1)); continue; } assert(r&1); printf("%lld\n", query(1, l/2+1, r/2+1, 0)); } return 0; }

Compilation message (stderr)

xoranges.cpp: In function 'int main()':
xoranges.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
xoranges.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         scanf("%d", &op);
      |         ~~~~~^~~~~~~~~~~
xoranges.cpp:82:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |             scanf("%d%d", &k, &u);
      |             ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         scanf("%d%d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~
#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...