Submission #35656

# Submission time Handle Problem Language Result Execution time Memory
35656 2017-11-27T08:46:50 Z dqhungdl Simple game (IZhO17_game) C++14
0 / 100
0 ms 33816 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX=10;
int n,T,a[100005],tree[4000005],lazy[4000005];

void Down(int k)
{
    tree[2*k]+=lazy[k];
    lazy[2*k]+=lazy[k];
    tree[2*k+1]+=lazy[k];
    lazy[2*k+1]+=lazy[k];
    lazy[k]=0;
}

void Update(int k,int l,int r,int L,int R,int val)
{
    if(l>R||L>r)
        return;
    if(L<=l&&r<=R)
    {
        tree[k]+=val;
        lazy[k]+=val;
        return;
    }
    Down(k);
    int mid=(l+r)/2;
    Update(2*k,l,mid,L,R,val);
    Update(2*k+1,mid+1,r,L,R,val);
}

int Query(int k,int l,int r,int pos)
{
    if(l==r)
        return tree[k];
    Down(k);
    int mid=(l+r)/2;
    if(pos<=mid)
        return Query(2*k,l,mid,pos);
    return Query(2*k+1,mid+1,r,pos);
}

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("TEST.INP","r",stdin);
    cin>>n>>T;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=2;i<=n;i++)
        Update(1,1,MAX,min(a[i-1],a[i]),max(a[i-1],a[i]),1);
    for(int i=2;i<n;i++)
        Update(1,1,MAX,a[i],a[i],-1);
    int type,pos,val;
    while(T--)
    {
        cin>>type;
        if(type==1)
        {
            cin>>pos>>val;
            if(pos>1)
                Update(1,1,MAX,min(a[pos-1],a[pos]),max(a[pos-1],a[pos]),-1);
            if(pos<n)
                Update(1,1,MAX,min(a[pos],a[pos+1]),max(a[pos],a[pos+1]),-1);
            if(1<pos&&pos<n)
                Update(1,1,MAX,a[pos],a[pos],1);
            a[pos]=val;
            if(pos>1)
                Update(1,1,MAX,min(a[pos-1],a[pos]),max(a[pos-1],a[pos]),-1);
            if(pos<n)
                Update(1,1,MAX,min(a[pos],a[pos+1]),max(a[pos],a[pos+1]),-1);
            if(1<pos&&pos<n)
                Update(1,1,MAX,a[pos],a[pos],1);
        }
        else
        {
            cin>>val;
            cout<<Query(1,1,MAX,val)<<"\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 33816 KB Output is correct
2 Incorrect 0 ms 33816 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 33816 KB Output is correct
2 Incorrect 0 ms 33816 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 33816 KB Output is correct
2 Incorrect 0 ms 33816 KB Output isn't correct
3 Halted 0 ms 0 KB -