제출 #1352767

#제출 시각아이디문제언어결과실행 시간메모리
1352767nijatXORanges (eJOI19_xoranges)C++20
100 / 100
158 ms7240 KiB
#include <iostream>   // cin, cout
#include <vector>     // vector
#include <algorithm>  // sort, find
#include <string>     // string
#include <map>        // map
#include <set>        // set
#include <queue>      // queue, priority_queue
#include <stack>      // stack
#include <cmath>      // math functions

#define int long long
using namespace std;

const int N = 2e5 + 5;
const int INF = 1e18;
const int mod = 1e9 + 7;

int a[N], st[2][2 * N];
void update(int l, int r, int node, bool t, int x, int i)
{
    if (i < l or i > r) return ;
    if (l == r) {
        st[t][node] = x;
        return ;
    }
    int mid = (l + r) / 2;
    update(l, mid, node * 2, t, x, i);
    update(mid + 1, r, node * 2 + 1, t, x, i);
    st[t][node] = (st[t][node * 2] ^ st[t][node * 2 + 1]);
}
int getans(int l, int r, int node, int ql, int qr, int t)
{
    if (r < ql or qr < l)   return 0;
    if (ql <= l and r <= qr)    return st[t][node];
    int mid = (l + r) / 2;
    return (getans(l, mid, node * 2, ql, qr, t) ^ getans(mid + 1, r, node * 2 + 1, ql, qr, t));
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        update(1, (n + 1) / 2, 1, i % 2, a[i], (i + 1) / 2);
    }
    while (q --) {
        int t, i, j;    cin >> t >> i >> j;
        if (t == 1) {
            update(1, (n + 1) / 2, 1, i % 2, j, (i + 1) / 2);
        }
        else {
            if ((j - i + 1) % 2 == 0) {
                cout << 0 << endl;
                continue ;
            }
            cout << getans(1, (n + 1) / 2, 1, (i + 1) / 2, (j + 1) / 2, i % 2) << endl;
        }
    }

}
#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...