답안 #382504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382504 2021-03-27T13:22:48 Z Lord_Zebellak XORanges (eJOI19_xoranges) C++14
100 / 100
688 ms 16492 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector <ll> vi;
typedef pair<ll,ll> pll;
#define mp make_pair
#define pb push_back
#define N ((ll)(2e5 + 5))
#define INF ((ll)1e18+18)
#define bismillah {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

ll n,m;

ll st[4*N];
ll st2[4*N];
ll v[N];

void build1(ll l , ll r , ll i){
    if (l==r ){
        st[i] = v[l];
        return;
    }
    ll tm = (l + r) >> 1;
    build1(l, tm, 2*i);
    build1(tm+1, r, 2*i+1);
    st[i] = st[2*i] ^ st[2*i+1];
}

void build2(ll l , ll r , ll i){
    if (l==r ){
        // that means
        // if index is even st value is 0
        st2[i] = v[l] * (l%2);
        return;
    }
    ll tm = (l + r) >> 1;
    build2(l, tm, 2*i);
    build2(tm+1, r, 2*i+1);
    st2[i] = st2[2*i] ^ st2[2*i+1];
}

void update(ll l , ll r , ll pos , ll i , ll val){
    
    if (pos > r or pos < l)return;
    if (l == r){st[i] = val;return;}
    
    ll tm = (l+r)>>1;
    if (pos <= tm) update(l, tm, pos, 2*i, val);
    else update(tm+1,r,pos , 2*i+1, val);
    st[i] = st[2*i] ^ st[2*i+1];
}
void update2(ll l , ll r , ll pos , ll i , ll val){
    
    if (pos > r or pos < l)return;
    if (l == r){st2[i] = val * (l%2);return;}
    
    ll tm = (l+r)>>1;
    if (pos <= tm) update2(l, tm, pos, 2*i, val);
    else update2(tm+1,r,pos , 2*i+1, val);
    st2[i] = st2[2*i] ^ st2[2*i+1];
}

ll query(ll l , ll r , ll ql , ll qr , ll i){
    if (ql > r or qr < l)return 0;
    if (ql<=l and r <= qr) return st[i];
    ll tm = (l+r)>>1;
    return query(l, tm,ql, qr, 2*i) ^ query(tm+1, r, ql, qr, 2*i+1);
}
ll query2(ll l , ll r , ll ql , ll qr , ll i){
    if (ql > r or qr < l)return 0;
    if (ql<=l and r <= qr) return st2[i];
    ll tm = (l+r)>>1;
    return query2(l, tm,ql, qr, 2*i) ^ query2(tm+1, r, ql, qr, 2*i+1);
}



int main(){
    
    bismillah
 
    cin >> n >> m;
    
    for (ll i = 0 ; i < n ; i ++){
        cin >> v[i];
    }
    build1(0, n-1, 1);
    build2(0, n-1, 1);
    
    for (ll j = 0; j < m ; j++){
        ll t , l , r;
        cin >> t >> l >> r;
        if (t == 1){
            update(0, n-1, l-1, 1, r);
            update2(0, n-1, l-1, 1, r);
        }else {
            if ((r-l+1)%2 == 0){
                cout << 0 << endl;
            }else {
                ll q1 = query(0, n-1, l-1, r-1, 1);
                ll q2 = query2(0, n-1, l-1, r-1, 1);
                if (l%2==0){
                    cout << q2 << endl;
                }else {
                    cout << (q2 ^ q1) << endl;
                }
            }
            
        }
    }
    
    
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 12 ms 620 KB Output is correct
12 Correct 10 ms 620 KB Output is correct
13 Correct 15 ms 620 KB Output is correct
14 Correct 15 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 681 ms 14060 KB Output is correct
2 Correct 688 ms 16140 KB Output is correct
3 Correct 675 ms 16492 KB Output is correct
4 Correct 617 ms 16000 KB Output is correct
5 Correct 615 ms 15884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 12 ms 620 KB Output is correct
12 Correct 10 ms 620 KB Output is correct
13 Correct 15 ms 620 KB Output is correct
14 Correct 15 ms 620 KB Output is correct
15 Correct 681 ms 14060 KB Output is correct
16 Correct 688 ms 16140 KB Output is correct
17 Correct 675 ms 16492 KB Output is correct
18 Correct 617 ms 16000 KB Output is correct
19 Correct 615 ms 15884 KB Output is correct
20 Correct 453 ms 16108 KB Output is correct
21 Correct 445 ms 15980 KB Output is correct
22 Correct 469 ms 16108 KB Output is correct
23 Correct 614 ms 15980 KB Output is correct
24 Correct 593 ms 15980 KB Output is correct