Submission #168147

#TimeUsernameProblemLanguageResultExecution timeMemory
168147GioChkhaidzeWeighting stones (IZhO11_stones)C++14
100 / 100
77 ms7548 KiB
#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 (stderr)

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);
   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...