답안 #1089828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089828 2024-09-17T08:58:34 Z KasymK XORanges (eJOI19_xoranges) C++17
100 / 100
117 ms 15368 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 2e5+5;
int v[2][N];

struct node{
    int l, r;
    ll sum;
} seg[2][N<<2];

void build(int x, int l, int r, int id){
    seg[id][x].l = l, seg[id][x].r = r;
    if(l == r){
        seg[id][x].sum = v[id][l];
        return;
    }
    int mid = (l+r)>>1;
    build(x<<1, l, mid, id);
    build(x<<1|1, mid+1, r, id);
    seg[id][x].sum = seg[id][x<<1].sum^seg[id][x<<1|1].sum;
}

void update(int x, int k, int u, int id){
    if(seg[id][x].l == seg[id][x].r){
        seg[id][x].sum = u;
        return;
    }
    int mid = (seg[id][x].l+seg[id][x].r)>>1;
    if(k <= mid)
        update(x<<1, k, u, id);
    else
        update(x<<1|1, k, u, id);
    seg[id][x].sum = seg[id][x<<1].sum^seg[id][x<<1|1].sum;
}

ll query(int x, int l, int r, int id){
    if(seg[id][x].l == l and seg[id][x].r == r)
        return seg[id][x].sum;
    int mid = (seg[id][x].l+seg[id][x].r)>>1;
    if(r <= mid)
        return query(x<<1, l, r, id);
    else if(l > mid)
        return query(x<<1|1, l, r, id);
    else
        return (query(x<<1, l, mid, id)^query(x<<1|1, mid+1, r, id));
}

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    int pk = 0, pk1 = 0;
    for(int i = 1; i <= n; ++i){
        int x;
        scanf("%d", &x);
        if(i&1)
            v[0][++pk] = x;
        else
            v[1][++pk1] = x;
    }
    // There is no updates
    build(1, 1, pk, 0);
    if(n > 1)
        build(1, 1, pk1, 1);
    // 0-tak, 1-jubut
    while(q--){
        int op;
        scanf("%d", &op);
        if(op == 1){
            int k, u;
            scanf("%d%d", &k, &u);
            if(k&1)
                update(1, k/2+1, u, 0);
            else
                update(1, k/2, u, 1);
            continue;
        }
        int l, r;
        scanf("%d%d", &l, &r);
        int wow = r-l+1;
        if(wow%2 == 0){
            puts("0");
            continue;
        }
        if(l%2 == 0){
            assert(r%2 == 0);
            printf("%lld\n", query(1, l/2, r/2, 1));
            continue;
        }
        assert(r&1);
        printf("%lld\n", query(1, l/2+1, r/2+1, 0));
    }
    return 0;
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
xoranges.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         scanf("%d", &op);
      |         ~~~~~^~~~~~~~~~~
xoranges.cpp:82:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |             scanf("%d%d", &k, &u);
      |             ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         scanf("%d%d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 440 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 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 440 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 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 15232 KB Output is correct
2 Correct 113 ms 15368 KB Output is correct
3 Correct 104 ms 15292 KB Output is correct
4 Correct 88 ms 14964 KB Output is correct
5 Correct 80 ms 14936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 440 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 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 3 ms 856 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 117 ms 15232 KB Output is correct
16 Correct 113 ms 15368 KB Output is correct
17 Correct 104 ms 15292 KB Output is correct
18 Correct 88 ms 14964 KB Output is correct
19 Correct 80 ms 14936 KB Output is correct
20 Correct 100 ms 14976 KB Output is correct
21 Correct 100 ms 15072 KB Output is correct
22 Correct 110 ms 15184 KB Output is correct
23 Correct 89 ms 14928 KB Output is correct
24 Correct 96 ms 15056 KB Output is correct