Submission #1015893

# Submission time Handle Problem Language Result Execution time Memory
1015893 2024-07-07T02:43:56 Z tuannm XORanges (eJOI19_xoranges) C++17
100 / 100
78 ms 8788 KB
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 2e5 + 1;
const string NAME = "";
int n, q, a[N];
int tree[2][N];

void update(int x, int id, int v){
    for(int i = id; i <= n; i += (i & -i))
        tree[x][i] ^= v;
}

int getnode(int x, int id){
    int ans = 0;
    for(int i = id; i > 0; i -= (i & -i))
        ans ^= tree[x][i];
    return ans;
}

int getval(int l, int r){
    if((r - l + 1) & 1)
        return getnode(r % 2, r) ^ getnode(r % 2, l - 1);
    return 0;
}

void inp(){
    cin >> n >> q;
    for(int i = 1; i <= n; ++i)
        cin >> a[i], update(i % 2, i, a[i]);
}

void solve(){
    while(q--){
        int t, x, y;
        cin >> t >> x >> y;
        if(t == 1){
            update(x % 2, x, a[x]);
            a[x] = y;
            update(x % 2, x, a[x]);
        }
        else{
            cout << getval(x, y) << "\n";
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen((NAME + ".inp").c_str(), "r")){
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }

    inp();
    solve();
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 8788 KB Output is correct
2 Correct 60 ms 8788 KB Output is correct
3 Correct 60 ms 8784 KB Output is correct
4 Correct 57 ms 8528 KB Output is correct
5 Correct 56 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 55 ms 8788 KB Output is correct
16 Correct 60 ms 8788 KB Output is correct
17 Correct 60 ms 8784 KB Output is correct
18 Correct 57 ms 8528 KB Output is correct
19 Correct 56 ms 8276 KB Output is correct
20 Correct 63 ms 8528 KB Output is correct
21 Correct 69 ms 8472 KB Output is correct
22 Correct 78 ms 8324 KB Output is correct
23 Correct 56 ms 8332 KB Output is correct
24 Correct 59 ms 8272 KB Output is correct