Submission #1327595

#TimeUsernameProblemLanguageResultExecution timeMemory
1327595sh_qaxxorov_571XORanges (eJOI19_xoranges)C++20
100 / 100
61 ms3968 KiB
#include <iostream>
#include <vector>

using namespace std;

/**
 * Xoranges Çözümü
 * Formül: Aralığın uzunluğu çift ise cevap 0'dır.
 * Tek ise, L ile aynı pariteye sahip indekslerin XOR toplamıdır.
 */

const int MAXN = 200005;
int bit[2][MAXN]; // bit[0] çift indeksler, bit[1] tek indeksler için
int n, q;
int a[MAXN];

// Fenwick Tree Güncelleme
void update(int t, int idx, int val) {
    for (; idx <= n; idx += idx & -idx) {
        bit[t][idx] ^= val;
    }
}

// Fenwick Tree Sorgu
int query(int t, int idx) {
    int res = 0;
    for (; idx > 0; idx -= idx & -idx) {
        res ^= bit[t][idx];
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    if (!(cin >> n >> q)) return 0;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        // İndeksin paritesine göre (i%2) ilgili BIT'e ekle
        update(i % 2, i, a[i]);
    }

    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int i, x;
            cin >> i >> x;
            // Mevcut değeri XOR ile çıkarıp yenisini ekleyerek güncelleme yapıyoruz
            update(i % 2, i, a[i] ^ x);
            a[i] = x;
        } else {
            int l, r;
            cin >> l >> r;
            // KURAL: Aralık uzunluğu çift ise sonuç 0
            if ((r - l + 1) % 2 == 0) {
                cout << 0 << "\n";
            } else {
                // KURAL: L ile aynı paritedeki elemanların aralık XOR toplamı
                int res = query(l % 2, r) ^ query(l % 2, l - 1);
                cout << res << "\n";
            }
        }
    }

    return 0;
}
#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...