답안 #35658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
35658 2017-11-27T08:49:22 Z dqhungdl Simple game (IZhO17_game) C++14
22 / 100
203 ms 41628 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX=1e6;
int n,T,a[100005],tree[5000005],lazy[5000005];

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";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 41628 KB Output is correct
2 Correct 3 ms 41628 KB Output is correct
3 Correct 9 ms 41628 KB Output is correct
4 Correct 3 ms 41628 KB Output is correct
5 Correct 9 ms 41628 KB Output is correct
6 Correct 9 ms 41628 KB Output is correct
7 Correct 3 ms 41628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 41628 KB Output is correct
2 Correct 3 ms 41628 KB Output is correct
3 Correct 9 ms 41628 KB Output is correct
4 Correct 3 ms 41628 KB Output is correct
5 Correct 9 ms 41628 KB Output is correct
6 Correct 9 ms 41628 KB Output is correct
7 Correct 3 ms 41628 KB Output is correct
8 Runtime error 203 ms 41628 KB Execution timed out (wall clock limit exceeded)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 41628 KB Output is correct
2 Correct 3 ms 41628 KB Output is correct
3 Correct 9 ms 41628 KB Output is correct
4 Correct 3 ms 41628 KB Output is correct
5 Correct 9 ms 41628 KB Output is correct
6 Correct 9 ms 41628 KB Output is correct
7 Correct 3 ms 41628 KB Output is correct
8 Runtime error 203 ms 41628 KB Execution timed out (wall clock limit exceeded)
9 Halted 0 ms 0 KB -