답안 #638560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638560 2022-09-06T11:40:05 Z ShirleyM XORanges (eJOI19_xoranges) C++14
0 / 100
350 ms 11308 KB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define x first
#define y second
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()
#define fast {ios_base::sync_with_stdio(false); cin.tie(0);}
const int inf = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;

struct seg{
    vi a; int sz;
    bool odd;

    seg(int n, bool odd) : odd(odd){
        for(sz=1;sz<n;sz<<=1);
        a.resize(2*sz);
    }

    void update(int ind, int val){
        if((odd && ind%2) || (!odd && ind%2==0)){
            ind+=sz; a[ind] = val;
            for(ind>>=1;ind;ind>>=1)
                a[ind] = a[2*ind]^a[2*ind+1];
        }
    }

    int query(int l, int r){
        int ans=0;
        l+=sz; r+=sz;
        while(l<=r){
            if(l%2) ans^=a[l++];
            if(r%2==0) ans^=a[r--];
            l>>=1; r>>=1;
        }
        return ans;
    }
};

int32_t main() {
    fast;
    int n,q; cin >> n >> q;
    seg odd(n, 1), even(n, 0);
    loop(i,0,n){
        int a; cin >> a;
        odd.update(i,a);
        even.update(i,a);
    }
    loop(i,0,q){
        int op; cin >> op;
        if(op==1){
            int ind, val; cin >> ind >> val;
            ind--;
            odd.update(ind,val);
            even.update(ind,val);
        }
        else{
            int l,r; cin >> l >> r; l--; r--;
            int ans = 0;
            if(l%2) ans = odd.query(l,r);
            else ans = even.query(l,r);
            cout << ans << endl;
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 350 ms 11308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -