Submission #1068861

#TimeUsernameProblemLanguageResultExecution timeMemory
1068861adrielcpXORanges (eJOI19_xoranges)C++17
0 / 100
1065 ms2560 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define debug(x) cout << #x << " " << (x) << endl; #define all(x) x.begin(), x.end() void pp(pair<int, int>&a) { cout << "{" << a.first << ", " << a.second << endl; } void g(vector<int>&a) { cout << "{"; for (auto el : a) cout << el << ", "; cout << "}" << endl; } void g(vector<pair<int, int>>&a) { cout << "{"; for (auto el : a) pp(el); cout << "}" << endl; } #define DBG struct Seg { vector<int> seg, a; Seg(vector<int> &b) { a = b; seg = vector<int>(a.size()*4); } void build(int idx, int l, int r) { if (l == r) seg[idx] = a[l]; else { int mid = (l+r)>>1; build(idx*2, l, mid); build(idx*2+1, mid+1, r); seg[idx] = seg[idx*2] ^ seg[idx*2+1]; } } int query(int idx, int l, int r, int ql, int qr) { if (l > qr || r < ql || l > r) return 0; if (l >= ql && r <= qr) return seg[idx]; int mid = (l+r)>>1; return query(idx*2, l, mid, ql, qr) ^ query(idx*2+1, mid+1, r, ql, qr); } void update(int idx, int l, int r, int i, int v) { if (l == r) seg[idx] = v; else { int mid = (l+r)>>1; if (i <= mid) update(idx*2, l, mid, i, v); else update(idx*2+1, mid+1, r, i, v); seg[idx] = seg[idx*2] ^ seg[idx*2+1]; } } }; void solve() { int n,q;cin>>n>>q; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; // even // 2 4 6 8 // 1 2 3 4 // x/2 // 1 3 5 7 9 10 (odd) // 1 2 3 4 5 6 // x/2 + 1 vector<int> odd{0}, even{0}; for (int i = 0; i < n; i++) { if (i % 2 == 0) odd.push_back(a[i]); else even.push_back(a[i]); } Seg seg_odd(odd), seg_even(even); seg_odd.build(1, 1, odd.size()); seg_even.build(1, 1, even.size()); while (q--) { int t,x,y;cin>>t>>x>>y; if (t==1) { // upd // update(1, 1, n, x, y); if (x % 2 == 0) seg_even.update(1, 1, even.size(), x/2, y); else seg_odd.update(1, 1, odd.size(), x/2+1, y); } else { if ((y-x+1) % 2 == 0) cout << 0 << endl; else { if (x % 2 == 0) cout << seg_even.query(1, 1, even.size(), x/2, y/2) << endl; else cout << seg_odd.query(1, 1, odd.size(), x/2+1, y/2+1) << endl; } } } // g(a); } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(NULL); int t=1; #ifdef DBG freopen("inp1.txt", "r", stdin); freopen("out.txt", "w", stdout); cin>>t; #endif while (t--) { solve(); cout << endl; } return 0; }

Compilation message (stderr)

xoranges.cpp: In function 'int32_t main()':
xoranges.cpp:91:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |   freopen("inp1.txt", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:92:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   freopen("out.txt", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...