Submission #334316

# Submission time Handle Problem Language Result Execution time Memory
334316 2020-12-09T02:35:51 Z nandonathaniel Weighting stones (IZhO11_stones) C++14
100 / 100
74 ms 5612 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005;

int tree[2][4*MAXN],lazy[2][4*MAXN];

void updatenode(int no,int now,int L,int R,int val){
	tree[no][now]+=val;
	lazy[no][now]+=val;
}

void pushdown(int no,int now,int L,int R){
	int mid=(L+R)/2;
	updatenode(no,2*now,L,mid,lazy[no][now]);
	updatenode(no,2*now+1,mid+1,R,lazy[no][now]);
	lazy[no][now]=0;
}

int query(int no,int now,int L,int R,int x,int y){
	if(L>=x && R<=y)return tree[no][now];
	if(L>y || R<x)return 0;
	pushdown(no,now,L,R);
	int mid=(L+R)/2;
	return max(query(no,2*now,L,mid,x,y),query(no,2*now+1,mid+1,R,x,y));
}

void update(int now,int L,int R,int x,int y,int val){
	if(L>=x && R<=y){
		updatenode(0,now,L,R,val);
		updatenode(1,now,L,R,val);
		return;
	}
	if(L>y || R<x)return;
	int mid=(L+R)/2;
	pushdown(0,now,L,R);
	pushdown(1,now,L,R);
	update(2*now,L,mid,x,y,val);
	update(2*now+1,mid+1,R,x,y,val);
	tree[0][now]=min(tree[0][2*now],tree[0][2*now+1]);
	tree[1][now]=max(tree[1][2*now],tree[1][2*now+1]);
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,id,x;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> x >> id;
		if(id==1){
			update(1,1,n,1,x,1);
		}
		else{
			update(1,1,n,1,x,-1);
		}
		int besar=query(1,1,1,n,1,n),kecil=query(0,1,1,n,1,n);
		if(besar>0){
			if(kecil>=0)cout << '>';
			else cout << '?';
		}
		else{
			if(kecil<=0)cout << '<';
			else cout << '?';
		}
		cout << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 6 ms 1004 KB Output is correct
11 Correct 44 ms 2924 KB Output is correct
12 Correct 74 ms 5356 KB Output is correct
13 Correct 67 ms 5484 KB Output is correct
14 Correct 69 ms 5484 KB Output is correct
15 Correct 67 ms 5484 KB Output is correct
16 Correct 67 ms 5484 KB Output is correct
17 Correct 67 ms 5484 KB Output is correct
18 Correct 67 ms 5484 KB Output is correct
19 Correct 67 ms 5400 KB Output is correct
20 Correct 68 ms 5484 KB Output is correct
21 Correct 69 ms 5612 KB Output is correct
22 Correct 67 ms 5484 KB Output is correct
23 Correct 69 ms 5484 KB Output is correct
24 Correct 67 ms 5484 KB Output is correct
25 Correct 68 ms 5484 KB Output is correct