#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss secox
#define all(v) v.begin(), v.ex()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
const int MAX = 1e6;
int v[N], F[MAX+7];
int main(){
// freopen("file.txt", "r", stdin);
int n, q;
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; ++i){
int x;
scanf("%d", &x);
v[i] = x;
}
auto wow = [&](int k, int u) {
for(; k <= MAX; k += k&-k)
F[k] += u;
};
auto how = [&](int a, int b, int val) {
if(a>b)
swap(a, b);
wow(a, val);
wow(b+1, val);
};
for(int i = 1; i < n; ++i)
how(v[i], v[i+1], 1);
while(q--){
int op;
scanf("%d", &op);
if(op==1){
int k, u;
scanf("%d%d", &k, &u);
if(k>1)
how(v[k], v[k-1], -1);
if(k<n)
how(v[k], v[k+1], -1);
v[k] = u;
if(k>1)
how(v[k], v[k-1], 1);
if(k<n)
how(v[k], v[k+1], 1);
continue;
}
int k;
scanf("%d", &k);
int answer = 0;
for(; k >= 1; k -= k&-k)
answer += F[k];
printf("%d\n", answer);
}
return 0;
}
Compilation message
game.cpp: In function 'int main()':
game.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
game.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
game.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d", &op);
| ~~~~~^~~~~~~~~~~
game.cpp:45:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d%d", &k, &u);
| ~~~~~^~~~~~~~~~~~~~~~
game.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d", &k);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |