Submission #1017331

# Submission time Handle Problem Language Result Execution time Memory
1017331 2024-07-09T07:25:27 Z MrPavlito XORanges (eJOI19_xoranges) C++17
100 / 100
185 ms 20556 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>

using namespace std;

const int MAXN = 2e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;

vector<int> paranseg(MAXN<<2);
vector<int> neparanseg(MAXN<<2);
vector<int> niz(MAXN);
int n;

void build(int nod, int l, int r)
{
    if(l==r)
    {
        if(l&1)neparanseg[nod] = niz[l];
        else paranseg[nod] = niz[l];
        return;
    }
    int mid = l+r>>1;
    build(nod<<1, l, mid);
    build(nod<<1|1, mid+1, r);
    neparanseg[nod] = neparanseg[nod<<1]^neparanseg[nod<<1|1];
    paranseg[nod] = paranseg[nod<<1]^paranseg[nod<<1|1];
}

void update(int nod,int l, int r, int index, int v, vector<int>&seg)
{

    if(l==r)
    {
        seg[nod] = v;
        niz[l] = v;
        return;
    }
    int mid = l+r>>1;
    if(index<=mid)update(nod<<1,l, mid, index, v, seg);
    else update(nod<<1|1,mid+1, r, index, v, seg);
    seg[nod] = seg[nod<<1|1] ^ seg[nod<<1];
}

int query(int nod, int tl, int tr, int l, int r, vector<int>&seg)
{
    if(tl>r || tr<l || tl>tr)return 0;
    if(tl>=l && tr<=r)return seg[nod];
    int mid = tl+tr>>1;
    return query(nod<<1, tl, mid, l, r,seg)^query(nod<<1|1, mid+1, tr, l, r,seg);
}

int query(int l, int r)
{
    if((r-l+1)&1)
    {
        int trazeni = (r-l)/2+1;
        if(l&1)return query(1,1,n,l,r,neparanseg);
        return query(1,1,n,l,r,paranseg);
    }
    return 0;
}

signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
    int tt=1;
    //cin >> tt;
    while(tt--)
    {
        int q;
        cin >> n >> q;

        for(int i=1; i<=n; i++)cin >> niz[i];
        build(1,1,n);
        while(q--)
        {
            int c,a,b;
            cin >> c >> a >> b;
            if(c==1)
            {
                ///update
                if(a&1)update(1,1,n,a,b,neparanseg);
                else update(1,1,n,a,b,paranseg);
            }
            else
            {
                ///query
                cout << query(a,b)<< endl;
            }
        }
    }
}

Compilation message

xoranges.cpp: In function 'void build(long long int, long long int, long long int)':
xoranges.cpp:30:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |     int mid = l+r>>1;
      |               ~^~
xoranges.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, std::vector<long long int>&)':
xoranges.cpp:46:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |     int mid = l+r>>1;
      |               ~^~
xoranges.cpp: In function 'long long int query(long long int, long long int, long long int, long long int, long long int, std::vector<long long int>&)':
xoranges.cpp:56:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |     int mid = tl+tr>>1;
      |               ~~^~~
xoranges.cpp: In function 'long long int query(long long int, long long int)':
xoranges.cpp:64:13: warning: unused variable 'trazeni' [-Wunused-variable]
   64 |         int trazeni = (r-l)/2+1;
      |             ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 5 ms 14428 KB Output is correct
5 Correct 5 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 5 ms 14548 KB Output is correct
3 Correct 5 ms 14428 KB Output is correct
4 Correct 4 ms 14428 KB Output is correct
5 Correct 5 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 5 ms 14428 KB Output is correct
5 Correct 5 ms 14428 KB Output is correct
6 Correct 5 ms 14428 KB Output is correct
7 Correct 5 ms 14548 KB Output is correct
8 Correct 5 ms 14428 KB Output is correct
9 Correct 4 ms 14428 KB Output is correct
10 Correct 5 ms 14428 KB Output is correct
11 Correct 6 ms 14684 KB Output is correct
12 Correct 6 ms 14684 KB Output is correct
13 Correct 5 ms 14684 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 20448 KB Output is correct
2 Correct 90 ms 20352 KB Output is correct
3 Correct 110 ms 20556 KB Output is correct
4 Correct 83 ms 20052 KB Output is correct
5 Correct 105 ms 20048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 5 ms 14428 KB Output is correct
5 Correct 5 ms 14428 KB Output is correct
6 Correct 5 ms 14428 KB Output is correct
7 Correct 5 ms 14548 KB Output is correct
8 Correct 5 ms 14428 KB Output is correct
9 Correct 4 ms 14428 KB Output is correct
10 Correct 5 ms 14428 KB Output is correct
11 Correct 6 ms 14684 KB Output is correct
12 Correct 6 ms 14684 KB Output is correct
13 Correct 5 ms 14684 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 86 ms 20448 KB Output is correct
16 Correct 90 ms 20352 KB Output is correct
17 Correct 110 ms 20556 KB Output is correct
18 Correct 83 ms 20052 KB Output is correct
19 Correct 105 ms 20048 KB Output is correct
20 Correct 91 ms 20308 KB Output is correct
21 Correct 185 ms 20292 KB Output is correct
22 Correct 104 ms 20284 KB Output is correct
23 Correct 82 ms 20184 KB Output is correct
24 Correct 81 ms 20048 KB Output is correct