#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
const int LIM = 1e6 + 5;
const int lim = 1e5 + 5;
int n, m, h[lim], bit[LIM];
void update(int p, int x){
for(; p < LIM; p += p & -p){
bit[p] += x;
}
}
void update(int l, int r, int x){
if(l > r){
swap(l, r);
}
update(l, x);
update(r + 1, -x);
}
int get(int p){
int ans = 0;
for(; p > 0; p -= p & -p){
ans += bit[p];
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> h[i];
}
memset(bit, 0, sizeof(bit));
for(int i = 1; i < n; i++){
update(h[i], h[i + 1], 1);
}
for(int _ = 0; _ < m; _++){
int _t;
cin >> _t;
if(_t == 1){
int p, v;
cin >> p >> v;
if(p > 1){
update(h[p], h[p - 1], -1);
update(v, h[p - 1], 1);
}
if(p < n){
update(h[p], h[p + 1], -1);
update(v, h[p + 1], 1);
}
h[p] = v;
}
else{
int u;
cin >> u;
cout << get(u) << "\n";
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In function 'int main()':
game.cpp:29:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |