Submission #958686

# Submission time Handle Problem Language Result Execution time Memory
958686 2024-04-06T10:32:00 Z M_SH_O XORanges (eJOI19_xoranges) C++14
100 / 100
473 ms 18064 KB
#pragma GCC optimize("O3")
#pragma GCC optimization("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
#include<bits/stdc++.h>
#define ll long long
#define dou long double
#define str string
#define pb push_back
#define fr first
#define se second
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define pll pair<ll, ll>
#define endl "\n"
 
using namespace std;
 
ll n;
ll a[200000];     
ll tree[800008];  
ll tree1[800008]; 


void build_tree1(int v, int tl, int tr) {
    if (tl == tr) 
    {
        if(tl % 2 == 1) tree1[v] = a[tl];
        else tree1[v] = 0;
    } else {
        int tm = (tl + tr) / 2;
        build_tree1(v * 2, tl, tm);
        build_tree1(v * 2 + 1, tm + 1, tr);
        tree1[v] = tree1[v * 2] ^ tree1[v * 2 + 1];
    }
}
int get_sum1(int l, int r, int v, int tl, int tr) {
    if (l <= tl && tr <= r) {
        return tree1[v];
    }
 
    if (tr < l || r < tl) {
        return 0;
    }
 
    int tm = (tl + tr) / 2;
    ll k = get_sum1(l, r, v * 2,     tl,     tm)
         ^ get_sum1(l, r, v * 2 + 1, tm + 1, tr);
    return k;
}






void build_tree(int v, int tl, int tr) {
    if (tl == tr) 
    {
        if(tl % 2 == 0) tree[v] = a[tl];
        else tree[v] = 0;
    } else {
        int tm = (tl + tr) / 2;
        build_tree(v * 2, tl, tm);
        build_tree(v * 2 + 1, tm + 1, tr);
        tree[v] = tree[v * 2] ^ tree[v * 2 + 1];
    }
}
int get_sum(int l, int r, int v, int tl, int tr) {
    if (l <= tl && tr <= r) {
        return tree[v];
    }
 
    if (tr < l || r < tl) {
        return 0;
    }
 
    int tm = (tl + tr) / 2;
    ll k = get_sum(l, r, v * 2,     tl,     tm)
         ^ get_sum(l, r, v * 2 + 1, tm + 1, tr);
    return k;
}
void update(int idx, int val, int v, int tl, int tr) 
{
    if (tl == tr) 
    {
        a[idx] = val;
        if(idx % 2 == 0) tree[v] = val;
        else tree1[v] = val;
        return;
    }
 
    int tm = (tl + tr) / 2;
    if(idx <= tm) update(idx, val, v * 2,     tl,     tm);
    else update(idx, val, v * 2 + 1, tm + 1, tr);
    tree[v] = tree[v * 2] ^ tree[v * 2 + 1];
    tree1[v] = tree1[v * 2] ^ tree1[v * 2 + 1];
}

 
int main()
{
    ll n, q, k, x, l, r;
    cin >> n >> q;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    build_tree(1, 0, n-1);
    build_tree1(1, 0, n-1);
    for(; q > 0; q --)
    {
        cin >> x >> l >> r;
        if(x == 1)
        {
            update(l-1, r, 1, 0, n-1);
        }
        else
        {
            k = 0;
            if((r-l+1) % 2 == 1) 
            {
                if(l % 2 == 1) k = get_sum(l-1, r-1, 1, 0, n-1);
                else k = get_sum1(l-1, r-1, 1, 0, n-1);
                //cout << "!!!" << endl;
            }
            
            cout << k << endl;
            
        }
    }
    
}

Compilation message

xoranges.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization("Ofast,unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2392 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 9 ms 4700 KB Output is correct
12 Correct 12 ms 4928 KB Output is correct
13 Correct 11 ms 4700 KB Output is correct
14 Correct 10 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 473 ms 15440 KB Output is correct
2 Correct 446 ms 16144 KB Output is correct
3 Correct 469 ms 16076 KB Output is correct
4 Correct 413 ms 15956 KB Output is correct
5 Correct 448 ms 15976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2392 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 9 ms 4700 KB Output is correct
12 Correct 12 ms 4928 KB Output is correct
13 Correct 11 ms 4700 KB Output is correct
14 Correct 10 ms 4700 KB Output is correct
15 Correct 473 ms 15440 KB Output is correct
16 Correct 446 ms 16144 KB Output is correct
17 Correct 469 ms 16076 KB Output is correct
18 Correct 413 ms 15956 KB Output is correct
19 Correct 448 ms 15976 KB Output is correct
20 Correct 329 ms 17992 KB Output is correct
21 Correct 325 ms 18064 KB Output is correct
22 Correct 327 ms 17952 KB Output is correct
23 Correct 420 ms 17880 KB Output is correct
24 Correct 412 ms 18000 KB Output is correct