제출 #1331825

#제출 시각아이디문제언어결과실행 시간메모리
1331825boclobanchatSimple game (IZhO17_game)C++20
100 / 100
57 ms5304 KiB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6+5;
int A[MAXN],fen[MAXN];
void update(int i,int n,int val) { for(;i<=n;i+=i&-i) fen[i]+=val; }
int get(int i) { int ans=0;for(;i;i-=i&-i) ans+=fen[i];return ans; }
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
    	cin>>A[i];
    	if(i>1)
    	{
    		update(min(A[i-1],A[i]),1e6,1);
    		update(max(A[i-1],A[i])+1,1e6,-1);
		}
	}
	while(q--)
	{
		int t;
		cin>>t;
		if(t==1)
		{
			int i,v;
			cin>>i>>v;
			if(i>1)
			{
				update(min(A[i-1],A[i]),1e6,-1);
    			update(max(A[i-1],A[i])+1,1e6,1);
			}
			if(i<n)
			{
				update(min(A[i+1],A[i]),1e6,-1);
    			update(max(A[i+1],A[i])+1,1e6,1);
			}
			A[i]=v;
			if(i>1)
			{
				update(min(A[i-1],A[i]),1e6,1);
    			update(max(A[i-1],A[i])+1,1e6,-1);
			}
			if(i<n)
			{
				update(min(A[i+1],A[i]),1e6,1);
    			update(max(A[i+1],A[i])+1,1e6,-1);
			}
		}
		else
		{
			int x;
			cin>>x;
			cout<<get(x)<<"\n";
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...