Submission #1015893

#TimeUsernameProblemLanguageResultExecution timeMemory
1015893tuannmXORanges (eJOI19_xoranges)C++17
100 / 100
78 ms8788 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...