Submission #466095

# Submission time Handle Problem Language Result Execution time Memory
466095 2021-08-17T22:15:02 Z urosk XORanges (eJOI19_xoranges) C++14
100 / 100
236 ms 17660 KB
// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x) long long
#define here cerr<<"---------------------------\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
using namespace std;
void setIO(string inoutname)
{
	freopen((inoutname+".in").c_str(),"r",stdin);
    	freopen((inoutname+".out").c_str(),"w",stdout);
}

ll gcd(ll a, ll b)
{
   if(b==0) return a;
   if(a==0) return b;
   if(a>=b)  return gcd(a%b,b);
   return  gcd(a,b%a);
}
#define maxn 200005
ll n;
ll a[maxn];
ll b[maxn];
ll sega[4*maxn];
ll segb[4*maxn];
void inita(ll v,ll l,ll r){
    if(l==r){
        sega[v] = a[l];
        return;
    }
    ll mid = (l+r)/2;
    inita(2*v,l,mid);
    inita(2*v+1,mid+1,r);
    sega[v] = sega[2*v]^sega[2*v+1];
}
ll xora(ll v,ll tl,ll tr,ll l,ll r){
    if(l>r) return 0;
    if(tl==l&&tr==r){
        return sega[v];
    }
    ll mid = (tl+tr)/2;
    return xora(2*v,tl,mid,l,min(mid,r))^xora(2*v+1,mid+1,tr,max(mid+1,l),r);
}
void upda(ll v,ll tl,ll tr,ll val,ll pos){
    if(tl==tr){
        a[tl] = val;
        sega[v] = val;
        return;
    }
    ll mid = (tl+tr)/2;
    if(pos<=mid) upda(2*v,tl,mid,val,pos);
    else upda(2*v+1,mid+1,tr,val,pos);
    sega[v] = sega[2*v]^sega[2*v+1];
}
void initb(ll v,ll l,ll r){
    if(l==r){
        segb[v] = b[l];
        return;
    }
    ll mid = (l+r)/2;
    initb(2*v,l,mid);
    initb(2*v+1,mid+1,r);
    segb[v] = segb[2*v]^segb[2*v+1];
}
ll xorb(ll v,ll tl,ll tr,ll l,ll r){
    if(l>r) return 0;
    if(tl==l&&tr==r){
        return segb[v];
    }
    ll mid = (tl+tr)/2;
    return xorb(2*v,tl,mid,l,min(mid,r))^xorb(2*v+1,mid+1,tr,max(mid+1,l),r);
}
void updb(ll v,ll tl,ll tr,ll val,ll pos){
    if(tl==tr){
        b[tl] = val;
        segb[v] = val;
        return;
    }
    ll mid = (tl+tr)/2;
    if(pos<=mid) updb(2*v,tl,mid,val,pos);
    else updb(2*v+1,mid+1,tr,val,pos);
    segb[v] = segb[2*v]^segb[2*v+1];
}
void tc(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    ll tip;
    cin >> tip;
    if(tip == 1){
        ll pos,val;
        cin >> pos >> val;
        if(pos&1) upda(1,1,n,val,pos);
        else updb(1,1,n,val,pos);
    }else{
        ll l,r;
        cin >> l >> r;
        if((r-l+1)%2==0) cout<<0<<endl;
        else{
            if(l&1) cout<<xora(1,1,n,l,r)<<endl;
            else cout<<xorb(1,1,n,l,r)<<endl;
        }
    }
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	//setIO("lol");
	int t; t = 1;
    cin >> n >> t;
    for(ll i = 1;i<=n;i++){
        if(i&1) cin >> a[i];
        else cin >> b[i];
    }
    inita(1,1,n);
    initb(1,1,n);
	while(t--){
		tc();
	}
	return 0;
}

Compilation message

xoranges.cpp: In function 'void setIO(std::string)':
xoranges.cpp:24:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:25:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 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 1 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 4 ms 716 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 4 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 13132 KB Output is correct
2 Correct 236 ms 17592 KB Output is correct
3 Correct 187 ms 17660 KB Output is correct
4 Correct 150 ms 17348 KB Output is correct
5 Correct 150 ms 17268 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
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 4 ms 716 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 4 ms 784 KB Output is correct
15 Correct 215 ms 13132 KB Output is correct
16 Correct 236 ms 17592 KB Output is correct
17 Correct 187 ms 17660 KB Output is correct
18 Correct 150 ms 17348 KB Output is correct
19 Correct 150 ms 17268 KB Output is correct
20 Correct 173 ms 17440 KB Output is correct
21 Correct 210 ms 17404 KB Output is correct
22 Correct 173 ms 17420 KB Output is correct
23 Correct 170 ms 17348 KB Output is correct
24 Correct 153 ms 17236 KB Output is correct