답안 #1078006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078006 2024-08-27T11:33:03 Z Acanikolic 돌 무게 재기 (IZhO11_stones) C++14
100 / 100
61 ms 7576 KB
#include <bits/stdc++.h>  

#define int long long 

#define pb push_back
 
#define F first
 
#define S second
 
using namespace std;
 
const int N = 1e5 + 10;
 
const int mod = 1e9 + 7;
 
const int inf = 1e9;

struct Node {
	int mn,mx;
};

Node st[N * 4];
int lazy[N * 4];

void push(int node,int tl,int tr) {
	st[node].mx += lazy[node];
	st[node].mn += lazy[node];
	if(tl != tr) {
		lazy[node * 2] += lazy[node];
		lazy[node * 2 + 1] += lazy[node];
	}
	lazy[node] = 0;
}

void modify(int node,int tl,int tr,int l,int r,int val) {
	push(node,tl,tr);
	if(tl > r || tr < l) return;
	if(tl >= l && tr <= r) {
		lazy[node] = val;
		push(node,tl,tr);
		return;
	} 
	int mid = (tl + tr) / 2;
	modify(node * 2,tl,mid,l,r,val);
	modify(node * 2 + 1,mid + 1,tr,l,r,val);
	st[node].mn = min(st[node * 2].mn,st[node * 2 + 1].mn);
	st[node].mx = max(st[node * 2].mx,st[node * 2 + 1].mx);
}

int getmn(int node,int tl,int tr,int l,int r) {
	push(node,tl,tr);
	if(tl > r || tr < l) return inf;
	if(tl >= l && tr <= r) return st[node].mn;
	int mid = (tl + tr) / 2;
	return min(getmn(node * 2,tl,mid,l,r),getmn(node * 2 + 1,mid + 1,tr,l,r));
}

int getmx(int node,int tl,int tr,int l,int r) {
	push(node,tl,tr);
	if(tl > r || tr < l) return -inf;
	if(tl >= l && tr <= r) return st[node].mx;
	int mid = (tl + tr) / 2;
	return max(getmx(node * 2,tl,mid,l,r),getmx(node * 2 + 1,mid + 1,tr,l,r));
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 	
 	int n;
 	cin >> n;
 	for(int i = 1; i <= n; i++) {
 		int x,y;
 		cin >> x >> y;
 		x = n - x + 1;
 		modify(1,1,n,x,n,(y == 1 ? 1 : -1));
 		if(getmn(1,1,n,1,n) >= 0) {
 			cout << ">\n";
 		}else if(getmx(1,1,n,1,n) <= 0) {
 			cout << "<\n";
 		}else {
 			cout << "?\n";
 		}
 	}
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 1292 KB Output is correct
11 Correct 37 ms 3932 KB Output is correct
12 Correct 41 ms 7248 KB Output is correct
13 Correct 36 ms 7504 KB Output is correct
14 Correct 61 ms 7504 KB Output is correct
15 Correct 37 ms 7532 KB Output is correct
16 Correct 36 ms 7508 KB Output is correct
17 Correct 57 ms 7556 KB Output is correct
18 Correct 61 ms 7504 KB Output is correct
19 Correct 53 ms 7504 KB Output is correct
20 Correct 36 ms 7512 KB Output is correct
21 Correct 57 ms 7576 KB Output is correct
22 Correct 58 ms 7504 KB Output is correct
23 Correct 42 ms 7504 KB Output is correct
24 Correct 42 ms 7492 KB Output is correct
25 Correct 46 ms 7504 KB Output is correct