답안 #48401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48401 2018-05-12T17:55:10 Z Pajaraja Simple game (IZhO17_game) C++17
100 / 100
97 ms 5520 KB
#include <bits/stdc++.h>
using namespace std;
int bit[1000007],a[100007];
int sum(int pos)
{
	int sol=0;
	while(pos)
	{
		sol+=bit[pos];
		pos-=(pos&-pos);
	}
	return sol;
}
void upd(int x,int pos)
{
	while(pos<=1000000)
	{
		bit[pos]+=x;
		pos+=(pos&-pos);
	}
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n-1;i++)
	{	
		upd(1,min(a[i],a[i+1]));
		upd(-1,max(a[i],a[i+1]));	
	}
	for(int i=0;i<m;i++)
	{
		int t;
		scanf("%d",&t);
		if(t==1)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			x--;
			if(x!=0)
			{
				upd(-1,min(a[x],a[x-1]));
				upd(1,max(a[x],a[x-1]));
			}
			if(x!=n-1)
			{
				upd(-1,min(a[x],a[x+1]));
				upd(1,max(a[x],a[x+1]));
			}
			a[x]=y;
			if(x!=0)
			{
				upd(1,min(a[x],a[x-1]));
				upd(-1,max(a[x],a[x-1]));
			}
			if(x!=n-1)
			{
				upd(1,min(a[x],a[x+1]));
				upd(-1,max(a[x],a[x+1]));
			}
		}
		else {int x; scanf("%d",&x); printf("%d\n",sum(x));}
	}
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:25: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:26:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%d",&a[i]);
                       ~~~~~^~~~~~~~~~~~
game.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&t);
   ~~~~~^~~~~~~~~
game.cpp:39:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d",&x,&y);
    ~~~~~^~~~~~~~~~~~~~
game.cpp:63:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   else {int x; scanf("%d",&x); printf("%d\n",sum(x));}
                ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 5 ms 4068 KB Output is correct
3 Correct 5 ms 4144 KB Output is correct
4 Correct 5 ms 4220 KB Output is correct
5 Correct 5 ms 4220 KB Output is correct
6 Correct 5 ms 4312 KB Output is correct
7 Correct 3 ms 4312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 5 ms 4068 KB Output is correct
3 Correct 5 ms 4144 KB Output is correct
4 Correct 5 ms 4220 KB Output is correct
5 Correct 5 ms 4220 KB Output is correct
6 Correct 5 ms 4312 KB Output is correct
7 Correct 3 ms 4312 KB Output is correct
8 Correct 57 ms 4312 KB Output is correct
9 Correct 74 ms 5500 KB Output is correct
10 Correct 75 ms 5520 KB Output is correct
11 Correct 55 ms 5520 KB Output is correct
12 Correct 61 ms 5520 KB Output is correct
13 Correct 62 ms 5520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 5 ms 4068 KB Output is correct
3 Correct 5 ms 4144 KB Output is correct
4 Correct 5 ms 4220 KB Output is correct
5 Correct 5 ms 4220 KB Output is correct
6 Correct 5 ms 4312 KB Output is correct
7 Correct 3 ms 4312 KB Output is correct
8 Correct 57 ms 4312 KB Output is correct
9 Correct 74 ms 5500 KB Output is correct
10 Correct 75 ms 5520 KB Output is correct
11 Correct 55 ms 5520 KB Output is correct
12 Correct 61 ms 5520 KB Output is correct
13 Correct 62 ms 5520 KB Output is correct
14 Correct 93 ms 5520 KB Output is correct
15 Correct 93 ms 5520 KB Output is correct
16 Correct 93 ms 5520 KB Output is correct
17 Correct 96 ms 5520 KB Output is correct
18 Correct 97 ms 5520 KB Output is correct