Submission #999695

# Submission time Handle Problem Language Result Execution time Memory
999695 2024-06-16T05:16:38 Z vjudge1 XORanges (eJOI19_xoranges) C++17
100 / 100
100 ms 19284 KB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define p_b pop_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll sz = 2e5+5;
ll a[sz], b[sz], segtree1[4*sz], segtree2[4*sz];
void build(ll v, ll l, ll r)
{
    if(l == r){
        segtree1[v] = a[l];
        segtree2[v] = b[l];
    }
    else
    {
        ll mid = (l + r) / 2;
        build(2*v, l, mid);
        build(2*v+1, mid+1, r);
        segtree1[v] = (segtree1[2*v] ^ segtree1[2*v+1]);
        segtree2[v] = (segtree2[2*v] ^ segtree2[2*v+1]);
    }
}
void update1(ll v, ll l, ll r, ll idx, ll val)
{
    if(l == r)
        segtree1[v] = val;
    else
    {
        ll mid = (l + r) / 2;
        if(idx <= mid)
            update1(2*v, l, mid, idx, val);
        else
            update1(2*v+1, mid+1, r, idx, val);
        segtree1[v] = (segtree1[2*v] ^ segtree1[2*v+1]);
    }
}
void update2(ll v, ll l, ll r, ll idx, ll val)
{
    if(l == r)
        segtree2[v] = val;
    else
    {
        ll mid = (l + r) / 2;
        if(idx <= mid)
            update2(2*v, l, mid, idx, val);
        else
            update2(2*v+1, mid+1, r, idx, val);
        segtree2[v] = (segtree2[2*v] ^ segtree2[2*v+1]);
    }
}
ll findans1(ll v, ll l, ll r, ll tl, ll tr)
{
    if(tl > tr)
        return 0;
    if(l == tl && r == tr)
        return segtree1[v];
    else
    {
        ll mid = (l + r) / 2;
        ll lans = findans1(2*v, l, mid, tl, min(mid, tr));
        ll rans = findans1(2*v+1, mid+1, r, max(mid+1, tl), tr);
        return (lans ^ rans);
    }
}
ll findans2(ll v, ll l, ll r, ll tl, ll tr)
{
    if(tl > tr)
        return 0;
    if(l == tl && r == tr)
        return segtree2[v];
    else
    {
        ll mid = (l + r) / 2;
        ll lans = findans2(2*v, l, mid, tl, min(mid, tr));
        ll rans = findans2(2*v+1, mid+1, r, max(mid+1, tl), tr);
        return (lans ^ rans);
    }
}
void solve()
{
    ll n, q, i, a1 = 1, b1 = 1;
    cin >> n >> q;
    for(i = 1; i <= n; i++)
    {
        ll x;
        cin >> x;
        if(i % 2)
            a[a1++] = x;
        else
            b[b1++] = x;
    }
    build(1, 1, n);
    while(q--)
    {
        ll type, l, r;
        cin >> type >> l >> r;
        if(type == 2)
        {
            if((r - l + 1) % 2)
            {
                if(l%2)
                {
                    if(r % 2 == 0)
                        r--;
                    cout << findans1(1, 1, n, (l+1)/2, (r+1)/2) << "\n";
                }
                else
                {
                    if(r % 2 == 1)
                        r--;
                    cout << findans2(1, 1, n, l/2, r/2) << "\n";
                }
            }
            else
                cout << "0\n";
        }
        else
        {
            if(l % 2)
                update1(1, 1, n, (l+1)/2, r);
            else
                update2(1, 1, n, l/2, r);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 4 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 2 ms 6832 KB Output is correct
14 Correct 2 ms 6720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 19280 KB Output is correct
2 Correct 78 ms 19280 KB Output is correct
3 Correct 79 ms 19284 KB Output is correct
4 Correct 68 ms 18772 KB Output is correct
5 Correct 65 ms 18772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 4 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 2 ms 6832 KB Output is correct
14 Correct 2 ms 6720 KB Output is correct
15 Correct 94 ms 19280 KB Output is correct
16 Correct 78 ms 19280 KB Output is correct
17 Correct 79 ms 19284 KB Output is correct
18 Correct 68 ms 18772 KB Output is correct
19 Correct 65 ms 18772 KB Output is correct
20 Correct 100 ms 18932 KB Output is correct
21 Correct 80 ms 18920 KB Output is correct
22 Correct 79 ms 19028 KB Output is correct
23 Correct 68 ms 18768 KB Output is correct
24 Correct 78 ms 18768 KB Output is correct