답안 #1099564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099564 2024-10-11T16:13:05 Z vjudge1 XORanges (eJOI19_xoranges) C++17
100 / 100
440 ms 11252 KB
#include <bits/stdc++.h>
using namespace std;

string abc = "abcdefghijklmnopqrstuvwxyz";


struct segTree{
    int sz;
    vector<int> t, a;
    void init(int n){
        sz = 1;
        while(sz < n) sz*=2;
        t.assign(2*sz, 0);
    }

    void merge(int v){
        t[v]=t[2*v]^t[2*v+1];
    }

    void inn(int v, int tl, int tr){
        if(tl == tr){
            t[v] = a[tl-1];
            return;
        }
        int tm = (tl+tr)/2;
        inn(2*v, tl, tm);
        inn(2*v+1, tm+1, tr);
        merge(v);
    }

    void in(int n, vector<int> va){
        a = va;
        inn(1, 1, n);
        for(int i = 1; i <= n; i++){
        }
    }

    int get(int v, int tl, int tr, int l, int r){
        // if(min(v, tl) < 0) return 33;
        if(tl == l && tr == r){
            return t[v];
        }
        int tm = (tl+tr)/2;
        if(tm >= r) return get(2*v, tl, tm, l, r);
        if(tm < l) return get(2*v+1, tm+1, tr, l, r);
        int ga = get(2*v, tl, tm, l, tm), gb = get(2*v+1, tm+1, tr, tm+1, r);
        return ga^gb;
    }

    void upd(int v, int tl, int tr, int pos, int va){
        if(tl == tr){
            t[v]=va;
            return;
        }
        int tm = (tl+tr)/2;
        if(tm >= pos) upd(2*v, tl, tm, pos, va);
        else upd(2*v+1, tm+1, tr, pos, va);
        merge(v);
    }

};



signed  main(){
    int n, q;
    cin >> n >> q;
    vector<int> v(n+1);
    for(int i = 1; i <= n; i++) cin >> v[i];
    segTree sa, sb;
    sa.init(n/2+2);
    sb.init(n/2+2);
    vector<int> ra, rb;
    for(int i = 1; i <= n; i++){
        if(i%2 == 1){
            ra.push_back(v[i]);
        }
        else rb.push_back(v[i]);
    }

    sa.in(ra.size(), ra);
    sb.in(rb.size(), rb);
    int na = ra.size();
    int nb = rb.size();
     n = n/2+2;
    while(q--){
        int qu;
        cin >> qu;
        if(qu == 1){
            int p, va;
            cin >> p >> va;
            if(p%2 == 0){
                int np = p/2;
                sb.upd(1, 1, nb, np, va);
            }
            else{
                int np = p/2+1;
                sa.upd(1, 1, na, np, va);
            }
        }
        else{
            int l, r;
            cin >> l >> r;
            if((r-l+1)%2 == 0){
                cout << 0 << endl;
            }
            else if(l%2 == 0){
                int ll = l/2, rr = r/2;
                int ans = sb.get(1, 1, nb, ll, rr);
                cout << ans << endl;
            }
            else{
                int ll = (l+1)/2, rr = (r+1)/2;
                int ans = sa.get(1, 1, na, ll, rr);
                cout << ans << endl;
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 7 ms 604 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 9 ms 700 KB Output is correct
14 Correct 9 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 440 ms 6304 KB Output is correct
2 Correct 413 ms 11252 KB Output is correct
3 Correct 362 ms 11080 KB Output is correct
4 Correct 350 ms 10816 KB Output is correct
5 Correct 359 ms 10816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 7 ms 604 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 9 ms 700 KB Output is correct
14 Correct 9 ms 604 KB Output is correct
15 Correct 440 ms 6304 KB Output is correct
16 Correct 413 ms 11252 KB Output is correct
17 Correct 362 ms 11080 KB Output is correct
18 Correct 350 ms 10816 KB Output is correct
19 Correct 359 ms 10816 KB Output is correct
20 Correct 270 ms 10916 KB Output is correct
21 Correct 278 ms 10784 KB Output is correct
22 Correct 279 ms 10812 KB Output is correct
23 Correct 364 ms 10820 KB Output is correct
24 Correct 354 ms 10768 KB Output is correct