#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n,q;
int bit1[1000005];
int bit2[1000005];
void apd1(int x, int val){
while(x <= 1000000){
bit1[x] += val;
x += (x&-x);
}
}
int kv1(int x){
int ans = 0;
while(x > 0){
ans += bit1[x];
x -= (x&-x);
}
return ans;
}
void apd2(int x, int val){
while(x <= 1000000){
bit2[x] += val;
x += (x&-x);
}
}
int kv2(int x){
int ans = 0;
while(x > 0){
ans += bit2[x];
x -= (x&-x);
}
return ans;
}
int niz[1000005];
void izbaci(int pos){
if(pos > 1 && niz[pos] != niz[pos - 1]){
if(niz[pos] == min(niz[pos], niz[pos - 1])){
apd1(niz[pos], -1);
}
else apd2(niz[pos], -1);
}
if(pos < n && niz[pos] != niz[pos + 1]){
if(niz[pos] == min(niz[pos], niz[pos + 1])){
apd1(niz[pos], -1);
}
else apd2(niz[pos], -1);
}
}
void ubaci(int pos, int val){
niz[pos] = val;
if(pos > 1 && niz[pos] != niz[pos - 1]){
if(niz[pos] == min(niz[pos], niz[pos - 1])){
apd1(niz[pos], 1);
}
else apd2(niz[pos], 1);
}
if(pos < n && niz[pos] != niz[pos + 1]){
if(niz[pos] == min(niz[pos], niz[pos + 1])){
apd1(niz[pos], 1);
}
else apd2(niz[pos], 1);
}
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> q;
ff(i,1,n){
cin >> niz[i];
}
ff(i,1,n - 1){
if(niz[i] == niz[i + 1])continue;
apd1(min(niz[i],niz[i + 1]), 1);
apd2(max(niz[i],niz[i + 1]), 1);
}
while(q--){
int idx;
cin >> idx;
if(idx == 2){
int h;
cin >> h;
cout << kv1(h) - kv2(h) << "\n";
}
else{
int pos,val;
cin >> pos >> val;
izbaci(pos);
ubaci(pos, val);
}
}
return 0;
}
Compilation message
game.cpp: In function 'int main()':
game.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
game.cpp:94:5: note: in expansion of macro 'ff'
94 | ff(i,1,n){
| ^~
game.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
game.cpp:97:5: note: in expansion of macro 'ff'
97 | ff(i,1,n - 1){
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
4 ms |
6380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
4 ms |
6380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
4 ms |
6380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |