Submission #167405

# Submission time Handle Problem Language Result Execution time Memory
167405 2019-12-08T08:41:11 Z GioChkhaidze Simple game (IZhO17_game) C++14
0 / 100
3 ms 376 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
using namespace std;
const int N=1e6+5;
int n,m,L,R,type,idx,val,dl,res;
int a[N],v[6*N];

void Upd(Tree) {
	if (r<L || R<l) return ;
	if (L<=l && r<=R) { v[h]+=dl; return ; }
	Upd(Left),Upd(Right);
}

void Get(Tree) {
	if (idx<l || r<idx) return ;
	if (l==idx && r==idx) { res+=v[h]; return ; }
	Get(Left),Get(Right);
	res+=v[h];
}

main () {
	scanf("%d%d",&n,&m);
	
	for (int i=1; i<=n; i++) {
		scanf("%d",&a[i]);
		if (i==1) continue;
		L=min(a[i],a[i-1])+1,R=max(a[i],a[i-1])-1,dl=1;
		if (L<=R) Upd(1,1,n);
	}
	
	while (m--) {
		scanf("%d",&type);
		if (type==1) {
			scanf("%d%d",&idx,&val);
			
			if (idx!=1) {
				L=min(a[idx],a[idx-1])+1;
				R=max(a[idx],a[idx-1])-1;
				dl=-1;
				if (L<=R) Upd(1,1,n);
			}
			
			if (idx!=n) {
				L=min(a[idx],a[idx+1])+1;
				R=max(a[idx],a[idx+1])-1;
				dl=-1;
				if (L<=R) Upd(1,1,n);
			}
			
			a[idx]=val;
			
			if (idx!=1) {
				L=min(a[idx],a[idx-1])+1;
				R=max(a[idx],a[idx-1])-1;
				dl=1;
				if (L<=R) Upd(1,1,n);
			}
			
			if (idx!=n) {
				L=min(a[idx],a[idx+1])+1;
				R=max(a[idx],a[idx+1])-1;
				dl=1;
				if (L<=R) Upd(1,1,n);
			}	
		}
			else {
			scanf("%d",&idx);
			res=0;
			Get(1,1,n);
			printf("%d\n",res);	
		}
	}
}

Compilation message

game.cpp:23:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
game.cpp: In function 'int main()':
game.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
game.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
game.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&type);
   ~~~~~^~~~~~~~~~~~
game.cpp:36:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d",&idx,&val);
    ~~~~~^~~~~~~~~~~~~~~~~~
game.cpp:69:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&idx);
    ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -