Submission #843609

# Submission time Handle Problem Language Result Execution time Memory
843609 2023-09-04T08:42:02 Z Esgeer XORanges (eJOI19_xoranges) C++17
100 / 100
94 ms 14244 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,O3,unroll-loops")
#define int long long
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>
#define vll vector<ll>
#define vvll vector<vll>
#define vb vector<bool>
#define vvb vector<vb>
#define endl "\n"
#define sp << " " <<
#define debug cout << "Working!" << endl; return;
#define F(i, s, n) for(int i = s; i < n; i++)
#define pb push_back
int inf = (~(1ll << (sizeof(int) * 8 - 1))) >> 1;
int mod = 1e9 + 7;
 
int add(int x, int y) {
    int sum ((x % mod) + (y % mod));
    if(sum >= mod) return sum - mod;
    else return sum;
}
int sadd(int x, int y) {
    return (x + y >= mod ? x + y - mod : x + y);
}
 
string FILENAME = "";
void setIO() {
    ios::sync_with_stdio(0); cin.tie(0);
    if(FILENAME == "") {
        #ifdef Local
            freopen("in.txt", "r", stdin);
            freopen("out.txt", "w", stdout);
        #endif
    } else {
        freopen((FILENAME + ".in").c_str(), "r", stdin);
        freopen((FILENAME + ".out").c_str(), "w", stdin);
    }
}

const int N = 1e5;
int a1[N], a2[N], t1[N*4], t2[N*4];
int build1(int node, int l, int r) {
    if(l == r) return t1[node] = a1[l];
    int m = (l + r) >> 1;
    return t1[node] = (build1(node*2, l, m) ^ build1(node*2+1, m+1, r));
}
int build2(int node, int l, int r) {
    if(l == r) return t2[node] = a2[l];
    int m = (l + r) >> 1;
    return t2[node] = (build2(node*2, l, m) ^ build2(node*2+1, m+1, r));
}
int query1(int node, int l, int r, int L, int R) {
    if(l > R || r < L) return 0;
    if(l >= L && r <= R) return t1[node];
    int m = (l + r) >> 1;
    return (query1(node*2, l, m, L, R) ^ query1(node*2+1, m+1, r, L, R));
}
int query2(int node, int l, int r, int L, int R) {
    if(l > R || r < L) return 0;
    if(l >= L && r <= R) return t2[node];
    int m = (l + r) >> 1;
    return (query2(node*2, l, m, L, R) ^ query2(node*2+1, m+1, r, L, R));
}
void update1(int node, int l, int r, int idx, int val) {
    if(l > idx || r < idx) return;
    if(l == r) { t1[node] = val; return; }
    int m = (l + r) / 2;
    update1(node*2, l, m, idx, val);
    update1(node*2+1, m+1, r, idx, val);
    t1[node] = t1[node*2] ^ t1[node*2+1];
}
void update2(int node, int l, int r, int idx, int val) {
    if(l > idx || r < idx) return;
    if(l == r) { t2[node] = val; return; }
    int m = (l + r) / 2;
    update2(node*2, l, m, idx, val);
    update2(node*2+1, m+1, r, idx, val);
    t2[node] = t2[node*2] ^ t2[node*2+1];
}

void solve() {
    int n, q;
    cin >> n >> q;
    F(i, 0, (n+1)/2) {
        cin >> a1[i];
        if((n&1) == 0 || i < n/2) cin >> a2[i];
    }
    int n1 = (n+1)/2, n2 = n/2;
    build1(1, 0, n1-1);
    build2(1, 0, n2-1);
    F(i, 0, q) {
        int type;
        cin >> type;
        if(type == 2) {
            int l, r;
            cin >> l >> r;
            l--, r--;
            int len = r - l + 1;
            if((len & 1) == 0) {
                cout << 0 << endl;
                continue;
            }
            if(l & 1) {
                cout << query2(1, 0, n2-1, l/2, r/2) << endl;
            } else {
                cout << query1(1, 0, n1-1, l/2, r/2) << endl;
            }
        } else {
            int i, v;
            cin >> i >> v;
            i--;
            if(i & 1) {
                update2(1, 0, n1-1, i/2, v);
            } else {
                update1(1, 0, n1-1, i/2, v);
            }
        }
    }
}
 
signed main() {
    setIO();
    int t = 1;
    //cin >> t;
    while(t--) solve();
}

Compilation message

xoranges.cpp: In function 'void setIO()':
xoranges.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen((FILENAME + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen((FILENAME + ".out").c_str(), "w", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 3 ms 4696 KB Output is correct
12 Correct 3 ms 4700 KB Output is correct
13 Correct 2 ms 4696 KB Output is correct
14 Correct 2 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 14244 KB Output is correct
2 Correct 90 ms 14160 KB Output is correct
3 Correct 91 ms 14160 KB Output is correct
4 Correct 82 ms 14060 KB Output is correct
5 Correct 80 ms 13904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 3 ms 4696 KB Output is correct
12 Correct 3 ms 4700 KB Output is correct
13 Correct 2 ms 4696 KB Output is correct
14 Correct 2 ms 4696 KB Output is correct
15 Correct 89 ms 14244 KB Output is correct
16 Correct 90 ms 14160 KB Output is correct
17 Correct 91 ms 14160 KB Output is correct
18 Correct 82 ms 14060 KB Output is correct
19 Correct 80 ms 13904 KB Output is correct
20 Correct 94 ms 13904 KB Output is correct
21 Correct 89 ms 13960 KB Output is correct
22 Correct 84 ms 14020 KB Output is correct
23 Correct 89 ms 13908 KB Output is correct
24 Correct 83 ms 13904 KB Output is correct