Submission #523049

#TimeUsernameProblemLanguageResultExecution timeMemory
523049dxz05XORanges (eJOI19_xoranges)C++14
100 / 100
313 ms11832 KiB
//#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 998244353;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 1222;

struct Fenwick{
    vector<int> a;
    vector<int> f;

    void add(int x, int y){
        while (x < f.size()){
            f[x] ^= y;
            x += (-x & x);
        }
    }

    int get(int x){
        int res = 0;
        while (x > 0){
            res ^= f[x];
            x -= (-x & x);
        }
        return res;
    }

    void update(int i, int x){
        add(i, a[i]);
        a[i] = x;
        add(i, a[i]);
    }

    int get(int l, int r){
        return get(r) ^ get(l - 1);
    }

    void init(vector<int> aa){
        a = aa;
        f.resize(a.size());
        for (int i = 1; i < a.size(); i++) add(i, a[i]);
    }
};

void solve(int TC) {
    int n, q;
    cin >> n >> q;

    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++){
        if (i & 1) cin >> a[i]; else
            cin >> b[i];
    }

    Fenwick odd, even;
    odd.init(a);
    even.init(b);

    while (q--){
        int t;
        cin >> t;
        if (t == 1){
            int i, x;
            cin >> i >> x;
            if (i & 1) odd.update(i, x); else
                even.update(i, x);
        } else {
            int l, r;
            cin >> l >> r;
            if ((r - l + 1) % 2 == 0){
                cout << 0 << endl;
            } else {
                cout << (l % 2 == 1 ? odd.get(l, r) : even.get(l, r)) << endl;
            }
        }
    }

}

int main() {
    startTime = clock();
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int TC = 1;
    //cin >> TC;

    for (int test = 1; test <= TC; test++) {
        //debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

    cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;

    return 0;
}

Compilation message (stderr)

xoranges.cpp: In member function 'void Fenwick::add(int, int)':
xoranges.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         while (x < f.size()){
      |                ~~^~~~~~~~~~
xoranges.cpp: In member function 'void Fenwick::init(std::vector<int>)':
xoranges.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int i = 1; i < a.size(); i++) add(i, a[i]);
      |                         ~~^~~~~~~~~~
#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...