Submission #657821

#TimeUsernameProblemLanguageResultExecution timeMemory
657821cpp219XORanges (eJOI19_xoranges)C++17
100 / 100
191 ms11248 KiB
#include<bits/stdc++.h>
#define ll int
#define ld double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 2e5 + 9;
const ll mod = 1e9 + 7;

ll n,q,a[N];
ll st[4*N][2];

void upd(ll id,ll type,ll l,ll r,ll u,ll val){
    if (u < l||r < u) return;
    if (l == r){
        st[id][type] ^= val; return;
    }
    ll mid = (l + r)/2;
    upd(id*2,type,l,mid,u,val);
    upd(id*2 + 1,type,mid + 1,r,u,val);
    st[id][type] = st[id*2][type] ^ st[id*2 + 1][type];
}

ll Get(ll id,ll type,ll l,ll r,ll u,ll v){
    if (v < l||r < u) return 0;
    if (u <= l&&r <= v) return st[id][type];
    ll mid = (l + r)/2;
    return Get(id*2,type,l,mid,u,v) ^ Get(id*2 + 1,type,mid + 1,r,u,v);
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n>>q;
    for (ll i = 1;i <= n;i++){
        cin>>a[i];
        upd(1,i%2,1,n,i,a[i]);
    }
    while(q--){
        ll type; cin>>type;
        if (type == 1){
            ll pos,val; cin>>pos>>val;
            upd(1,pos%2,1,n,pos,a[pos]);
            a[pos] = val;
            upd(1,pos%2,1,n,pos,a[pos]);
        }
        else{
            ll l,r; cin>>l>>r;
            if ((r - l + 1)%2){
                cout<<Get(1,l%2,1,n,l,r)<<"\n";
            }
            else cout<<0<<"\n";
        }
    }
}
/* be confident */

Compilation message (stderr)

xoranges.cpp: In function 'int main()':
xoranges.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...