제출 #1094238

#제출 시각아이디문제언어결과실행 시간메모리
1094238SunbaeSimple game (IZhO17_game)C++17
0 / 100
2 ms4188 KiB
#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));
		}
	}
}

컴파일 시 표준 에러 (stderr) 메시지

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