Submission #275613

# Submission time Handle Problem Language Result Execution time Memory
275613 2020-08-20T06:45:42 Z JuliusMieliauskas XORanges (eJOI19_xoranges) C++14
100 / 100
139 ms 5368 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vll vector<long long>
#define MOD 1000000007
#define endl '\n'

typedef long long ll;

void print(vi v){
    cout<<"Contents of vector:\n";
    for(auto x : v) cout<<x<<" ";
    cout<<endl<<endl;
}

const int MAXN = 200009;
int ar[MAXN];
int n;

int fenodd[MAXN] = {0};
int feneven[MAXN] = {0};

void updodd(int p, int x) {
    for (int i = p; i < MAXN; i += i&(-i))
        fenodd[i] ^= x;
}
int getodd(int p) {
    // gauna sumą elementų nuo 1-ojo iki p-tojo
    int ret = 0;
    for (int i = p; i > 0; i -= i&(-i))
        ret ^= fenodd[i];
    return ret;
}
int getodd (int l, int r) {
    // gauna sumą elementų, kurių indeksai intervale [l; r]
    //cout<<"Getting "<<r<<" and "<<l<<endl;
    return getodd(r) ^ getodd(l-1);
}

void updeven(int p, int x) {
    for (int i = p; i < MAXN; i += i&(-i))
        feneven[i] ^= x;
}
int geteven(int p) {
    int ret = 0;
    for (int i = p; i > 0; i -= i&(-i))
        ret ^= feneven[i];
    return ret;
}
int geteven(int l, int r) {
    //cout<<"R: "<<r<<" L: "<<l-1<<endl;
    return geteven(r) ^ geteven(l-1);
}

void solve(){
    int q; cin>>n>>q;
    for(int i = 0; i<n; i++) cin>>ar[i];
    //cerr<<"0 0 "<<endl;
    //updodd(0, 0);
    //cerr<<"10101"<<endl;
    //updeven(0, 0);
    updodd(1, ar[0]);
    updeven(1, ar[1]);

    for(int i = 4; i<=n; i+=2) {
        updeven((i+1)/2, ar[i-1]);
    }

    for(int i = 3; i<=n; i+=2) {
        //cout<<"Updating "<<i<<endl;
        updodd((i+1)/2, ar[i-1]);
    }

    /*cout<<"Prefsodd: "<<endl;
    for(int i = 0; i<=n; i++) cout<<getodd(i)<<" ";
    cout<<endl<<endl;*/

    /*cout<<"Prefseven: "<<endl;
    for(int i = 0; i<=n; i++) cout<<geteven(i)<<" ";
    cout<<endl<<endl;*/

    for(int i = 0; i<q; i++){
        int type; cin>>type;
        if(type == 1){
            int ind, value; cin>>ind>>value;

            //cout<<"Updating "<<(ind+1)/2<<endl;
            if(ind%2) {
                updodd((ind+1)/2, getodd((ind+1)/2, (ind+1)/2));
                updodd((ind+1)/2, value);
            } else {
                updeven((ind+1)/2, geteven((ind+1)/2, (ind+1)/2));
                updeven((ind+1)/2, value);
            }

            /*cout<<"Prefsodd: "<<endl;
            for(int i = 0; i<=n; i++) cout<<getodd(i)<<" ";
            cout<<endl<<endl;*/

        } else {
            int from, to; cin>>from>>to;

            if((to-from+1)%2 == 0){
                cout<<"0"<<endl;
                continue;
            }

            if(from%2) {
                cout<<getodd(max(1, (from+1)/2), (to+1)/2)<<endl;
            } else {
                cout<<geteven(max(1, (from+1)/2), (to+1)/2)<<endl;
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    //ifstream cin("input.txt"); ofstream cout("output.txt");///cia failai

    //int T; cin>>T;
    int T = 1;

    for(int it = 1; it<=T; it++){
        solve();

    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 4 ms 640 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 3320 KB Output is correct
2 Correct 111 ms 3192 KB Output is correct
3 Correct 139 ms 3192 KB Output is correct
4 Correct 135 ms 3192 KB Output is correct
5 Correct 96 ms 3192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 4 ms 640 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 640 KB Output is correct
15 Correct 112 ms 3320 KB Output is correct
16 Correct 111 ms 3192 KB Output is correct
17 Correct 139 ms 3192 KB Output is correct
18 Correct 135 ms 3192 KB Output is correct
19 Correct 96 ms 3192 KB Output is correct
20 Correct 105 ms 4728 KB Output is correct
21 Correct 104 ms 4704 KB Output is correct
22 Correct 103 ms 4728 KB Output is correct
23 Correct 113 ms 5368 KB Output is correct
24 Correct 112 ms 5368 KB Output is correct