답안 #168147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168147 2019-12-11T15:29:09 Z GioChkhaidze 돌 무게 재기 (IZhO11_stones) C++14
100 / 100
77 ms 7548 KB
#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define Left 2*h,l,(l+r)/2
#define Right 2*h+1,(l+r)/2+1,r
#define ll long long
using namespace std;
const int N=1e5+5;
ll n,L,R,idx,type,dl;
typedef struct {ll m1; ll m2; ll add; } Node;
Node v[4*N];
void Shift(Tree) {
	v[h].m1+=v[h].add;
	v[h].m2+=v[h].add;
	if (l!=r) {
		v[2*h].add+=v[h].add;
		v[2*h+1].add+=v[h].add;		
	}
	v[h].add=0;
}

void Upd(Tree) {
	Shift(h,l,r);
	if (r<L || R<l) return ;
	if (L<=l && r<=R) { 
		v[h].add+=dl;
		Shift(h,l,r);
		return ;
	}
	Upd(Left),Upd(Right);
	v[h].m1=min(v[2*h].m1,v[2*h+1].m1);
	v[h].m2=max(v[2*h].m2,v[2*h+1].m2);
}

main () {
	scanf("%d",&n);
	
	for (int i=1; i<=n; i++) {
		scanf("%d%d",&idx,&type);
		
		if (type==1) {
			L=1,R=idx,dl=1;
			Upd(1,1,n);
		}
			else  {
			L=1,R=idx,dl=-1;
			Upd(1,1,n);
		}		
				
		if (v[1].m1>=0 && v[1].m2>=0) printf(">\n");
			else
		if (v[1].m1<=0 && v[1].m2<=0) printf("<\n");
			else printf("?\n");
	}
}

Compilation message

stones.cpp:34:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
stones.cpp: In function 'int main()':
stones.cpp:35:15: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  scanf("%d",&n);
             ~~^
stones.cpp:38:26: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%d%d",&idx,&type);
                ~~~~      ^
stones.cpp:38:26: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
stones.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
stones.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&idx,&type);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 8 ms 1144 KB Output is correct
11 Correct 44 ms 3960 KB Output is correct
12 Correct 77 ms 7328 KB Output is correct
13 Correct 71 ms 7416 KB Output is correct
14 Correct 71 ms 7544 KB Output is correct
15 Correct 73 ms 7548 KB Output is correct
16 Correct 72 ms 7492 KB Output is correct
17 Correct 74 ms 7416 KB Output is correct
18 Correct 72 ms 7416 KB Output is correct
19 Correct 72 ms 7416 KB Output is correct
20 Correct 72 ms 7544 KB Output is correct
21 Correct 72 ms 7416 KB Output is correct
22 Correct 73 ms 7544 KB Output is correct
23 Correct 72 ms 7416 KB Output is correct
24 Correct 73 ms 7428 KB Output is correct
25 Correct 72 ms 7416 KB Output is correct