/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
const int N = (int)1e6 + 7;
int tree[N * 4], add[N * 4];
void push(int v, int l, int r){
if(add[v] != 0){
tree[v] += (r - l + 1) * add[v];
if(l != r){
add[v*2] += add[v];
add[v*2+1] += add[v];
}
add[v] = 0;
}
}
int get(int v, int l, int r, int ql, int qr){
push(v, l, r);
if(l > qr || r < ql)return 0;
if(ql <= l and r <= qr)return tree[v];
int m = (l + r) / 2;
return get(v*2, l, m, ql, qr) + get(v*2+1, m+1, r, ql, qr);
}
void update(int v, int l, int r, int ql, int qr, int val){
push(v, l, r);
if(l > qr || r < ql)return ;
if(ql <= l and r <= qr){
tree[v] += (r - l + 1) * val;
if(l != r){
add[v*2] += val;
add[v*2+1] += val;
}
return ;
}
int m = (l + r) / 2;
update(v*2, l, m, ql, qr, val);
update(v*2+1, m+1, r, ql, qr, val);
tree[v] = tree[v*2] + tree[v*2+1];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie();
int n, q;
cin >> n >> q;
int a[n];
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n - 1; i++){
update(1, 1, N, min(a[i], a[i+1]), max(a[i], a[i+1]), 1);
}
while(q--){
int type;
cin >> type;
if(type == 1){
int i, x;
cin >> i >> x;
if(i > 0){
update(1, 1, N, min(a[i], a[i-1]), max(a[i], a[i-1]), -1);
}
if(i < n - 1){
update(1, 1, N, min(a[i], a[i+1]), max(a[i], a[i+1]), -1);
}
a[i] = x;
if(i > 0){
update(1, 1, N, min(a[i], a[i-1]), max(a[i], a[i-1]), 1);
}
if(i < n - 1){
update(1, 1, N, min(a[i], a[i+1]), max(a[i], a[i+1]), 1);
}
} else{
int h;
cin >> h;
cout << get(1, 1, N, h, h) << endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |