#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<LEN;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 |
8280 KB |
Output is correct |
2 |
Correct |
3 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8288 KB |
Output is correct |
4 |
Correct |
3 ms |
8184 KB |
Output is correct |
5 |
Correct |
3 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8288 KB |
Output is correct |
7 |
Correct |
4 ms |
8236 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 |
8284 KB |
Output is correct |
11 |
Correct |
5 ms |
8284 KB |
Output is correct |
12 |
Correct |
5 ms |
8280 KB |
Output is correct |
13 |
Correct |
5 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
5 ms |
8308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8184 KB |
Output is correct |
3 |
Correct |
4 ms |
8280 KB |
Output is correct |
4 |
Correct |
12 ms |
9052 KB |
Output is correct |
5 |
Correct |
22 ms |
9696 KB |
Output is correct |
6 |
Correct |
44 ms |
10292 KB |
Output is correct |
7 |
Correct |
52 ms |
11212 KB |
Output is correct |
8 |
Correct |
66 ms |
11844 KB |
Output is correct |
9 |
Correct |
117 ms |
14272 KB |
Output is correct |
10 |
Correct |
98 ms |
14500 KB |
Output is correct |
11 |
Correct |
127 ms |
16584 KB |
Output is correct |
12 |
Correct |
148 ms |
17552 KB |
Output is correct |
13 |
Correct |
142 ms |
17500 KB |
Output is correct |
14 |
Correct |
139 ms |
17372 KB |
Output is correct |
15 |
Correct |
142 ms |
17604 KB |
Output is correct |
16 |
Correct |
143 ms |
17604 KB |
Output is correct |
17 |
Correct |
140 ms |
17608 KB |
Output is correct |
18 |
Correct |
165 ms |
17592 KB |
Output is correct |
19 |
Correct |
151 ms |
17540 KB |
Output is correct |
20 |
Correct |
142 ms |
17788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8280 KB |
Output is correct |
2 |
Correct |
3 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8288 KB |
Output is correct |
4 |
Correct |
3 ms |
8184 KB |
Output is correct |
5 |
Correct |
3 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8288 KB |
Output is correct |
7 |
Correct |
4 ms |
8236 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 |
8284 KB |
Output is correct |
11 |
Correct |
5 ms |
8284 KB |
Output is correct |
12 |
Correct |
5 ms |
8280 KB |
Output is correct |
13 |
Correct |
5 ms |
8284 KB |
Output is correct |
14 |
Correct |
4 ms |
8284 KB |
Output is correct |
15 |
Correct |
5 ms |
8308 KB |
Output is correct |
16 |
Correct |
4 ms |
8280 KB |
Output is correct |
17 |
Correct |
4 ms |
8184 KB |
Output is correct |
18 |
Correct |
4 ms |
8280 KB |
Output is correct |
19 |
Correct |
12 ms |
9052 KB |
Output is correct |
20 |
Correct |
22 ms |
9696 KB |
Output is correct |
21 |
Correct |
44 ms |
10292 KB |
Output is correct |
22 |
Correct |
52 ms |
11212 KB |
Output is correct |
23 |
Correct |
66 ms |
11844 KB |
Output is correct |
24 |
Correct |
117 ms |
14272 KB |
Output is correct |
25 |
Correct |
98 ms |
14500 KB |
Output is correct |
26 |
Correct |
127 ms |
16584 KB |
Output is correct |
27 |
Correct |
148 ms |
17552 KB |
Output is correct |
28 |
Correct |
142 ms |
17500 KB |
Output is correct |
29 |
Correct |
139 ms |
17372 KB |
Output is correct |
30 |
Correct |
142 ms |
17604 KB |
Output is correct |
31 |
Correct |
143 ms |
17604 KB |
Output is correct |
32 |
Correct |
140 ms |
17608 KB |
Output is correct |
33 |
Correct |
165 ms |
17592 KB |
Output is correct |
34 |
Correct |
151 ms |
17540 KB |
Output is correct |
35 |
Correct |
142 ms |
17788 KB |
Output is correct |
36 |
Correct |
4 ms |
8280 KB |
Output is correct |
37 |
Correct |
4 ms |
8284 KB |
Output is correct |
38 |
Correct |
4 ms |
8284 KB |
Output is correct |
39 |
Correct |
13 ms |
9048 KB |
Output is correct |
40 |
Correct |
22 ms |
9760 KB |
Output is correct |
41 |
Correct |
36 ms |
10684 KB |
Output is correct |
42 |
Correct |
53 ms |
11740 KB |
Output is correct |
43 |
Correct |
70 ms |
12492 KB |
Output is correct |
44 |
Correct |
127 ms |
15992 KB |
Output is correct |
45 |
Correct |
102 ms |
15056 KB |
Output is correct |
46 |
Correct |
112 ms |
15304 KB |
Output is correct |
47 |
Correct |
167 ms |
17304 KB |
Output is correct |
48 |
Correct |
156 ms |
17632 KB |
Output is correct |
49 |
Correct |
152 ms |
17632 KB |
Output is correct |
50 |
Correct |
164 ms |
17356 KB |
Output is correct |
51 |
Correct |
150 ms |
17604 KB |
Output is correct |
52 |
Correct |
154 ms |
17644 KB |
Output is correct |
53 |
Correct |
155 ms |
17604 KB |
Output is correct |
54 |
Correct |
158 ms |
17640 KB |
Output is correct |
55 |
Correct |
169 ms |
17812 KB |
Output is correct |