답안 #1094238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094238 2024-09-29T06:29:18 Z Sunbae Simple game (IZhO17_game) C++17
0 / 100
2 ms 4188 KB
#include <bits/stdc++.h>
#define z exit(0)
using namespace std;
const int M = 1e6 + 5, N = 1e5 + 5;
int bit[M], a[N];
void upd(int i, int v){ for(; i<M; i+=i&-i) bit[i] += v;}
int qry(int i){ int r = 0; for(; i; i-=i&-i) r += bit[i]; return r;}
void UPD(int l, int r, int v){ upd(l, +v); upd(r+1, -v);}
signed main(){
	int n, q; scanf("%d %d", &n, &q);
	for(int i = 0; i<n; ++i){
		scanf("%d", a+i);
		if(i){
			int l = a[i-1], r = a[i];
			if(l > r) swap(l, r);
			++l; --r;
			if(l <= r) UPD(l, r, +1);
		}
	}
	while(q--){
		int t; scanf("%d", &t);
		if(t == 1){
			int i, v, l, r; scanf("%d %d", &i, &v); --i;
			if(i){
				l = a[i-1]; r = a[i];
				if(l > r) swap(l, r);
				++l; --r;
				if(l <= r) UPD(l, r, -1);
				a[i] = v;
				l = a[i-1]; r = a[i];
				if(l > r) swap(l, r);
				++l; --r;
				if(l <= r) UPD(l, r, +1);
			}
			if(i < n-1){
				l = a[i+1]; r = a[i];
				if(l > r) swap(l, r);
				++l; --r;
				if(l <= r) UPD(l, r, -1);
				a[i] = v;
				l = a[i+1]; r = a[i];
				if(l > r) swap(l, r);
				++l; --r;
				if(l <= r) UPD(l, r, +1);
			}
		}else{
			int h; scanf("%d", &h);
			printf("%d\n", qry(h));
		}
	}
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:10:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  int n, q; scanf("%d %d", &n, &q);
      |            ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("%d", a+i);
      |   ~~~~~^~~~~~~~~~~
game.cpp:21:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   int t; scanf("%d", &t);
      |          ~~~~~^~~~~~~~~~
game.cpp:23:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |    int i, v, l, r; scanf("%d %d", &i, &v); --i;
      |                    ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:47:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |    int h; scanf("%d", &h);
      |           ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 2 ms 4188 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 2 ms 4188 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 2 ms 4188 KB Output isn't correct
3 Halted 0 ms 0 KB -