답안 #650716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650716 2022-10-15T00:00:21 Z sofija6 XORanges (eJOI19_xoranges) C++14
100 / 100
160 ms 20304 KB
#include <bits/stdc++.h>
#define ll long long
#define MAXN 200010
using namespace std;
ll n,a[MAXN],m;
struct element
{
   ll even=0,odd=0,cnt=0;
};
struct seg_tree
{
    vector<element> st;
    element neutral_element;
    element Merge(element x,element y)
    {
        element z;
        z=x;
        z.cnt+=y.cnt;
        if (x.cnt&1)
        {
            z.even^=y.odd;
            z.odd^=y.even;
        }
        else
        {
            z.even^=y.even;
            z.odd^=y.odd;
        }
        return z;
    }
    void Init()
    {
        m=1;
        while (m<n)
            m <<= 1;
        st.resize(2*m,neutral_element);
    }
    void Build()
    {
        for (ll i=m;i<m+n;i++)
            st[i]={0,a[i-m+1],1};
        for (ll i=m-1;i>0;i--)
            st[i]=Merge(st[2*i],st[2*i+1]);
    }
    void Add(ll pos,ll val,ll x,ll lx,ll rx)
    {
        if (lx==rx)
        {
            st[x]={0,val,1};
            return;
        }
        ll mid=(lx+rx)/2;
        if (pos<=mid)
            Add(pos,val,2*x,lx,mid);
        else
            Add(pos,val,2*x+1,mid+1,rx);
        st[x]=Merge(st[2*x],st[2*x+1]);
    }
    element Calc(ll l,ll r,ll x,ll lx,ll rx)
    {
        if (lx>r || rx<l)
            return neutral_element;
        if (lx>=l && rx<=r)
            return st[x];
        ll mid=(lx+rx)/2;
        return Merge(Calc(l,r,2*x,lx,mid),Calc(l,r,2*x+1,mid+1,rx));
    }
};
seg_tree S;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll q,t,l,r;
    cin >> n >> q;
    for (ll i=1;i<=n;i++)
        cin >> a[i];
    S.Init();
    S.Build();
    while (q--)
    {
        cin >> t >> l >> r;
        if (t==1)
            S.Add(l,r,1,1,m);
        else
        {
            if ((r-l+1)&1)
                cout << S.Calc(l,r,1,1,m).odd << "\n";
            else
                cout << "0\n";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 5 ms 832 KB Output is correct
12 Correct 4 ms 828 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 18128 KB Output is correct
2 Correct 160 ms 20216 KB Output is correct
3 Correct 149 ms 20304 KB Output is correct
4 Correct 119 ms 19800 KB Output is correct
5 Correct 116 ms 19900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 5 ms 832 KB Output is correct
12 Correct 4 ms 828 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 151 ms 18128 KB Output is correct
16 Correct 160 ms 20216 KB Output is correct
17 Correct 149 ms 20304 KB Output is correct
18 Correct 119 ms 19800 KB Output is correct
19 Correct 116 ms 19900 KB Output is correct
20 Correct 141 ms 19948 KB Output is correct
21 Correct 150 ms 19940 KB Output is correct
22 Correct 138 ms 19952 KB Output is correct
23 Correct 120 ms 19884 KB Output is correct
24 Correct 127 ms 19836 KB Output is correct