답안 #523049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523049 2022-02-06T19:23:47 Z dxz05 XORanges (eJOI19_xoranges) C++14
100 / 100
313 ms 11832 KB
//#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

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]);
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 5 ms 588 KB Output is correct
12 Correct 5 ms 588 KB Output is correct
13 Correct 8 ms 580 KB Output is correct
14 Correct 8 ms 576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 11824 KB Output is correct
2 Correct 305 ms 11820 KB Output is correct
3 Correct 313 ms 11832 KB Output is correct
4 Correct 299 ms 11432 KB Output is correct
5 Correct 310 ms 11592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 5 ms 588 KB Output is correct
12 Correct 5 ms 588 KB Output is correct
13 Correct 8 ms 580 KB Output is correct
14 Correct 8 ms 576 KB Output is correct
15 Correct 307 ms 11824 KB Output is correct
16 Correct 305 ms 11820 KB Output is correct
17 Correct 313 ms 11832 KB Output is correct
18 Correct 299 ms 11432 KB Output is correct
19 Correct 310 ms 11592 KB Output is correct
20 Correct 207 ms 11632 KB Output is correct
21 Correct 193 ms 11584 KB Output is correct
22 Correct 194 ms 11572 KB Output is correct
23 Correct 285 ms 11468 KB Output is correct
24 Correct 285 ms 11492 KB Output is correct