답안 #136181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136181 2019-07-24T22:36:18 Z FedericoS Simple game (IZhO17_game) C++14
0 / 100
17 ms 476 KB
#include <iostream>
#include <set>
using namespace std;

int N,M;
int H[100005];
int t,x,y;
multiset<int> startUp, startDown, endUp, endDown;

void add(int i){
	if(i==-1 or i==N-1)
		return;
	if(H[i]<H[i+1]){
		startUp.insert(H[i]);
		endUp.insert(H[i+1]);
	}
	else{
		startDown.insert(H[i]);
		endDown.insert(H[i+1]);	
	}
}

void remove(int i){
	if(i==-1 or i==N-1)
		return;
	if(H[i]<H[i+1]){
		startUp.erase(H[i]);
		endUp.erase(H[i+1]);
	}
	else{
		startDown.erase(H[i]);
		endDown.erase(H[i+1]);	
	}
}

int query(int h){

	int a,b,res=0;

	a=b=0;
	for(int x:startUp)
		if(x<h)
			a++;
	for(int x:endUp)
		if(x<h)
			b++;
	res+=a-b;

	a=b=0;
	for(int x:startDown)
		if(x>h)
			a++;
	for(int x:endDown)
		if(x>h)
			b++;
	res+=a-b;

	return res;

}

void print(){
	cout<<"******\n";

	for(int x:startUp)
		cout<<x<<" ";
	cout<<"\n";

	for(int x:startDown)
		cout<<x<<" ";
	cout<<"\n";

	for(int x:endUp)
		cout<<x<<" ";
	cout<<"\n";

	for(int x:endDown)
		cout<<x<<" ";
	cout<<"\n";

	cout<<"******\n";
}

int main(){
	cin>>N>>M;
	for(int i=0;i<N;i++)
		cin>>H[i];

	for(int i=0;i<N-1;i++)
		add(i);

	while(M--){
		cin>>t;
		
		if(t==1){
			cin>>x>>y;
			x--;
			remove(x-1);
			remove(x);
			H[x]=y;
			add(x-1);
			add(x);
		}
		else{
			cin>>x;
			cout<<query(x)<<"\n";
		}
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 476 KB Output is correct
2 Correct 17 ms 248 KB Output is correct
3 Incorrect 17 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 476 KB Output is correct
2 Correct 17 ms 248 KB Output is correct
3 Incorrect 17 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 476 KB Output is correct
2 Correct 17 ms 248 KB Output is correct
3 Incorrect 17 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -