제출 #499388

#제출 시각아이디문제언어결과실행 시간메모리
499388ismoilovSimple game (IZhO17_game)C++14
100 / 100
55 ms6852 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
const int maxx = 1e6+6;
int tr[4*maxx];
int n, m;
void add(int x, int val){
	while(x < maxx){
		tr[x] += val;
		x += x & -x;
	}
}
void add(int l, int r, int val){
	if(l > r)
		swap(l, r);
	add(l, val);
	add(r+1, -val);
}
int get(int x){
	int s = 0;
	while(x > 0){
		s += tr[x];
		x -= x & -x;
	}
	return s;
}
int a[maxx];
void S()
{
	cin >> n >> m;
	fpp(i,1,n){
		cin >> a[i];
		if(i > 1)
			add(a[i-1], a[i], 1);
	}
	while(m--){
		int t;
		cin >> t;
		if(t == 1){
			int i, v;
			cin >> i >> v;
			if(i > 1)
				add(a[i-1], a[i], -1), add(a[i-1], v, 1);
			if(i < n)
				add(a[i], a[i+1], -1), add(v, a[i+1], 1);
			a[i] = v;
		}
		else{
			int i;
			cin >> i;
			cout << get(i) << "\n";
	// 		cout << get(i) - get(i-1) << "\n";
		}
	}
}
int main()
{
	IOS;
	S();
}

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

game.cpp: In function 'void S()':
game.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
game.cpp:37:2: note: in expansion of macro 'fpp'
   37 |  fpp(i,1,n){
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...