답안 #38635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38635 2018-01-05T07:40:11 Z MrPlany Simple game (IZhO17_game) C++14
100 / 100
146 ms 6472 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6, maxn=1e5+5;

int t[N+5],a[maxn];
int n;

void add(int k, int x) {
	while (k <= N) {
		t[k] += x;
		k += k&-k;
	}
}

void gosh(int a, int b, int val){
	if(a>b) swap(a,b);
	add(a,val);
	add(b+1,-val);
}

int sum(int k) {
	int s = 0;
	while (k >= 1) {
		s += t[k];
		k -= k&-k;
	}
	return s;
}

int main(){
	ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	scanf("%d",&n);
	
	int q;
	scanf("%d",&q);
	
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	for(int i=1;i<n;i++) gosh(a[i],a[i+1],1);
	int pos, val, type;
		
	while(q--){
		scanf("%d",&type);
	
		if(type==1){
			scanf("%d",&pos);
			scanf("%d",&val);
			if(pos>1) gosh(a[pos-1],a[pos],-1);
			if(pos<n) gosh(a[pos],a[pos+1],-1);
			a[pos] = val;
			if(pos>1) gosh(a[pos-1],a[pos],1);
			if(pos<n) gosh(a[pos],a[pos+1],1);
		}
		else{
			scanf("%d",&pos);
	
			printf("%d\n",sum(pos));
		}
		
	}
	
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:33:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
game.cpp:36:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
                ^
game.cpp:38:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d",a+i);
                                       ^
game.cpp:43:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&type);
                    ^
game.cpp:46:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&pos);
                    ^
game.cpp:47:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&val);
                    ^
game.cpp:55:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&pos);
                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6472 KB Output is correct
2 Correct 0 ms 6472 KB Output is correct
3 Correct 3 ms 6472 KB Output is correct
4 Correct 0 ms 6472 KB Output is correct
5 Correct 0 ms 6472 KB Output is correct
6 Correct 0 ms 6472 KB Output is correct
7 Correct 0 ms 6472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6472 KB Output is correct
2 Correct 0 ms 6472 KB Output is correct
3 Correct 3 ms 6472 KB Output is correct
4 Correct 0 ms 6472 KB Output is correct
5 Correct 0 ms 6472 KB Output is correct
6 Correct 0 ms 6472 KB Output is correct
7 Correct 0 ms 6472 KB Output is correct
8 Correct 73 ms 6472 KB Output is correct
9 Correct 116 ms 6472 KB Output is correct
10 Correct 103 ms 6472 KB Output is correct
11 Correct 69 ms 6472 KB Output is correct
12 Correct 96 ms 6472 KB Output is correct
13 Correct 76 ms 6472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6472 KB Output is correct
2 Correct 0 ms 6472 KB Output is correct
3 Correct 3 ms 6472 KB Output is correct
4 Correct 0 ms 6472 KB Output is correct
5 Correct 0 ms 6472 KB Output is correct
6 Correct 0 ms 6472 KB Output is correct
7 Correct 0 ms 6472 KB Output is correct
8 Correct 73 ms 6472 KB Output is correct
9 Correct 116 ms 6472 KB Output is correct
10 Correct 103 ms 6472 KB Output is correct
11 Correct 69 ms 6472 KB Output is correct
12 Correct 96 ms 6472 KB Output is correct
13 Correct 76 ms 6472 KB Output is correct
14 Correct 146 ms 6472 KB Output is correct
15 Correct 93 ms 6472 KB Output is correct
16 Correct 103 ms 6472 KB Output is correct
17 Correct 113 ms 6472 KB Output is correct
18 Correct 109 ms 6472 KB Output is correct