답안 #844527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844527 2023-09-05T13:52:37 Z konber XORanges (eJOI19_xoranges) C++14
100 / 100
116 ms 13476 KB
#include <iostream>
#include <vector>

using namespace std;

vector<int> st1, st2, a;

void build(int p, int L, int R){
    if(L==R){
        if(L%2==0) st1[p] = a[L];
        else st2[p] = a[L];
        return;
    }

    build(2*p, L, (L+R)/2);
    build(2*p+1, (L+R)/2+1, R);
    st1[p] = st1[2*p]^st1[2*p+1];
    st2[p] = st2[2*p]^st2[2*p+1];
}

void update(int p, int L, int R, int pos, int v){
    if(L==R){
        if(L%2==0) st1[p] = v;
        else st2[p] = v;
        return;
    }

    int mid=(L+R)/2;
    if(pos <= mid)
        update(2*p, L, mid, pos, v);
    else
        update(2*p+1, mid+1, R, pos, v);
    st1[p] = st1[2*p]^st1[2*p+1];
    st2[p] = st2[2*p]^st2[2*p+1];

}

int rsq1(int p, int L, int R, int i, int j){
    if(j < L || i > R) return 0;
    if(L >= i && R <= j) return st1[p];

    int mid=(L+R)/2;
    return rsq1(2*p, L, mid, i, j)^rsq1(2*p+1, mid+1, R, i, j);
}

int rsq2(int p, int L, int R, int i, int j){
    if(j < L || i > R) return 0;
    if(L >= i && R <= j) return st2[p];

    int mid=(L+R)/2;
    return rsq2(2*p, L, mid, i, j)^rsq2(2*p+1, mid+1, R, i, j);
}

int main()
{
    int N, Q;
    scanf("%d%d", &N, &Q);
    a.resize(N+1);
    st1.resize(4*N+1);
    st2.resize(4*N+1);
    for(int i=1; i <= N; i++)
        scanf("%d", &a[i]);

    build(1, 1, N);
    while(Q--){
        int q, i, j;
        scanf("%d%d%d", &q, &i, &j);
        if(q==1){
            update(1, 1, N, i, j);
        }
        else{
            int ans;
            if((i%2)!=(j%2)) ans=0;
            else if(i%2==0)  ans = rsq1(1, 1, N, i, j);
            else ans = rsq2(1, 1, N, i, j);
            printf("%d\n", ans);
        }
    }
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d%d", &N, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
xoranges.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         scanf("%d%d%d", &q, &i, &j);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 344 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 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 344 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 344 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 13392 KB Output is correct
2 Correct 107 ms 13476 KB Output is correct
3 Correct 108 ms 13392 KB Output is correct
4 Correct 103 ms 13008 KB Output is correct
5 Correct 101 ms 13136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 344 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 344 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 116 ms 13392 KB Output is correct
16 Correct 107 ms 13476 KB Output is correct
17 Correct 108 ms 13392 KB Output is correct
18 Correct 103 ms 13008 KB Output is correct
19 Correct 101 ms 13136 KB Output is correct
20 Correct 104 ms 13136 KB Output is correct
21 Correct 116 ms 13164 KB Output is correct
22 Correct 107 ms 13248 KB Output is correct
23 Correct 103 ms 13096 KB Output is correct
24 Correct 103 ms 12984 KB Output is correct