#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
#define _all(T) T.begin(),T.end()
const int mxn = 2e5+10;
const int LEN = 1e6;
struct BIT{
int bit[LEN];
BIT(){
memset(bit,0,sizeof(bit));
}
void modify(int p,int v){
for(;p<mxn;p+=p&-p)bit[p] += v;
return;
}
int getval(int s,int e = -1){
if(e==-1)swap(s,e);
int re = 0;
for(;e>0;e-= e&-e)re += bit[e];
s--;
for(;s>0;s-= s&-s)re -= bit[s];
return re;
}
};
int arr[mxn];
BIT bit1,bit2;
int N,Q;
vector<int> all;
pii req[mxn];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>Q;
for(int i = 1;i<=N;i++){
cin>>arr[i];
all.push_back(arr[i]);
}
all.push_back(-1);
for(int i = 1;i<=Q;i++){
int t;
cin>>t;
if(t == 2){
int a,b;
cin>>a>>b;
req[i] = pii(a,b);
all.push_back(b);
}
else{
int k;
cin>>k;
all.push_back(k);
req[i] = pii(-1,k);
}
}
sort(_all(all));all.resize(unique(_all(all))-all.begin());
for(int i = 0;i<=N+1;i++){
arr[i] = lower_bound(_all(all),arr[i])-all.begin();
bit2.modify(arr[i],1);
}
for(int i = 1;i<=N+1;i++){
bit1.modify(min(arr[i],arr[i-1]),1);
}
for(int i = 1;i<=Q;i++){
req[i].sc = lower_bound(_all(all),req[i].sc)-all.begin();
if(req[i].fs<0){
int tar = req[i].sc;
cout<<bit2.getval(tar,all.size())-bit1.getval(tar,all.size())<<'\n';
}
else{
auto [pos,val] = req[i];
bit2.modify(arr[pos],-1);
bit1.modify(min(arr[pos],arr[pos-1]),-1);
bit1.modify(min(arr[pos],arr[pos+1]),-1);
arr[pos] = val;
bit2.modify(arr[pos],1);
bit1.modify(min(arr[pos],arr[pos-1]),1);
bit1.modify(min(arr[pos],arr[pos+1]),1);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8284 KB |
Output is correct |
2 |
Correct |
3 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8128 KB |
Output is correct |
4 |
Correct |
4 ms |
8284 KB |
Output is correct |
5 |
Correct |
4 ms |
8316 KB |
Output is correct |
6 |
Correct |
4 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8244 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8536 KB |
Output is correct |
11 |
Correct |
4 ms |
8280 KB |
Output is correct |
12 |
Correct |
4 ms |
8284 KB |
Output is correct |
13 |
Correct |
4 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8284 KB |
Output is correct |
2 |
Correct |
4 ms |
8376 KB |
Output is correct |
3 |
Correct |
5 ms |
8280 KB |
Output is correct |
4 |
Correct |
12 ms |
9052 KB |
Output is correct |
5 |
Correct |
23 ms |
9696 KB |
Output is correct |
6 |
Correct |
35 ms |
10712 KB |
Output is correct |
7 |
Correct |
53 ms |
11736 KB |
Output is correct |
8 |
Correct |
70 ms |
12664 KB |
Output is correct |
9 |
Incorrect |
108 ms |
15816 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8284 KB |
Output is correct |
2 |
Correct |
3 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8128 KB |
Output is correct |
4 |
Correct |
4 ms |
8284 KB |
Output is correct |
5 |
Correct |
4 ms |
8316 KB |
Output is correct |
6 |
Correct |
4 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8244 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8536 KB |
Output is correct |
11 |
Correct |
4 ms |
8280 KB |
Output is correct |
12 |
Correct |
4 ms |
8284 KB |
Output is correct |
13 |
Correct |
4 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
4 ms |
8284 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8376 KB |
Output is correct |
18 |
Correct |
5 ms |
8280 KB |
Output is correct |
19 |
Correct |
12 ms |
9052 KB |
Output is correct |
20 |
Correct |
23 ms |
9696 KB |
Output is correct |
21 |
Correct |
35 ms |
10712 KB |
Output is correct |
22 |
Correct |
53 ms |
11736 KB |
Output is correct |
23 |
Correct |
70 ms |
12664 KB |
Output is correct |
24 |
Incorrect |
108 ms |
15816 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |