Submission #466085

# Submission time Handle Problem Language Result Execution time Memory
466085 2021-08-17T21:55:27 Z urosk XORanges (eJOI19_xoranges) C++14
0 / 100
168 ms 11584 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[maxn];
ll segb[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[mid] = sega[2*mid]^sega[2*mid+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,r,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;
    inita(2*v,l,mid);
    inita(2*v+1,mid+1,r);
    segb[mid] = segb[2*mid]^segb[2*mid+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,r,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==0) cout<<0<<endl;
        else{
            if(l&1) cout<<xora(1,1,n,l,r)<<endl;
            else cout<<xora(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 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 168 ms 11584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -