Submission #466784

# Submission time Handle Problem Language Result Execution time Memory
466784 2021-08-20T16:19:03 Z mtxas XORanges (eJOI19_xoranges) C++14
100 / 100
138 ms 14144 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define pll pair<ll, ll>
#define mii map<int, int>
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(x) ((int)x.size())
#define turbo() cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false)
#define _fre() freopen("input.txt", "r", stdin)
#define _for(a, b, c) for(int (a) = (b); (a) < (c); (a)++)
#define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
#define _forneq(a, b, c) for(int (a) = (b); (a) >= (c); (a)--)
#define _forn(a, b, c) for(int (a) = (b); (a) > (c); (a)--)
using namespace std;
/**********************************************************************************
                                STRUCTS
**********************************************************************************/

/**********************************************************************************
                               VARIABLES
**********************************************************************************/
#define int ll
const int maxn = 2e5+2;
int a[maxn];
int t[maxn<<1][2];
int N;
/**********************************************************************************
                               FUNCTIONS
**********************************************************************************/
void upd(int p, int val){
    int k = p%2;
    for(t[p+=N][k] = val; p>1; p>>=1){
        t[p>>1][k] = t[p][k] ^ t[p^1][k];
    }
}
int query(int l, int r, int k){
    int ans = 0; r++;
    for(l+=N, r+=N; l<r; r>>=1, l>>=1){
        if(r&1) ans^= t[--r][k];
        if(l&1) ans^= t[l++][k];
    }
    return ans;
}
/**********************************************************************************
                                 MAIN
**********************************************************************************/
signed main(){
   // _fre();
    turbo();
    int n, q; cin>>n>>q; N = n+1;
    _foreq(i, 1, n) cin>>a[i], upd(i, a[i]);
    _for(g, 0, q){
        int type; cin>>type;
        if(type == 1){
            int i, val; cin>>i>>val;
            upd(i, val);
            //cout<<"a["<<i<<"] = "<<val<<endl;
        }
        else if(type == 2){
            int l, r; cin>>l>>r;
           // cout<<"query("<<l<<", "<<r<<")\n";
            if((l&1) != (r&1)) cout<<0<<'\n';
            else cout<<query(l, r, l&1)<<'\n';
        }
    }
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:17:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   17 | #define _foreq(a, b, c) for(int (a) = (b); (a) <= (c); (a)++)
      |                                 ^
xoranges.cpp:57:5: note: in expansion of macro '_foreq'
   57 |     _foreq(i, 1, n) cin>>a[i], upd(i, a[i]);
      |     ^~~~~~
xoranges.cpp:16:31: warning: unnecessary parentheses in declaration of 'g' [-Wparentheses]
   16 | #define _for(a, b, c) for(int (a) = (b); (a) < (c); (a)++)
      |                               ^
xoranges.cpp:58:5: note: in expansion of macro '_for'
   58 |     _for(g, 0, q){
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 3 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 14080 KB Output is correct
2 Correct 134 ms 14144 KB Output is correct
3 Correct 138 ms 14120 KB Output is correct
4 Correct 119 ms 13824 KB Output is correct
5 Correct 119 ms 13776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 3 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 131 ms 14080 KB Output is correct
16 Correct 134 ms 14144 KB Output is correct
17 Correct 138 ms 14120 KB Output is correct
18 Correct 119 ms 13824 KB Output is correct
19 Correct 119 ms 13776 KB Output is correct
20 Correct 127 ms 13836 KB Output is correct
21 Correct 125 ms 13808 KB Output is correct
22 Correct 125 ms 13892 KB Output is correct
23 Correct 121 ms 13732 KB Output is correct
24 Correct 120 ms 13764 KB Output is correct