#include <bits/stdc++.h>
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
using namespace std;
int N, tree[400001], A[200000];
vector<int> x;
vector<pair<int,int>> Q;
void update(int n, int v)
{
for(++n;n;n-=n&-n) tree[n]+=v;
}
int get_cnt(int n)
{
int ret=0;
for(++n;n<=400000;n+=n&-n) ret+=tree[n];
return ret;
}
void set_value(int i, int m)
{
int v=i==0;
v+=(i && A[i-1]<A[i]);
v-=(i+1<N && A[i]<A[i+1]);
update(A[i],m*v);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
TEST(freopen("input.txt", "r", stdin));
TEST(freopen("output.txt", "w", stdout));
TEST(freopen("debug.txt", "w", stderr));
int M;
cin>>N>>M;
for(int i=0;i<N;i++) {
cin>>A[i];
x.push_back(A[i]);
}
Q.resize(M);
for(auto &[a,b]: Q) {
int t;
cin>>t>>a; b=-1;
if(t==2) {
cin>>b; --a;
x.push_back(b);
}
}
sort(x.begin(),x.end());
x.resize(unique(x.begin(),x.end())-x.begin());
for(int i=0;i<N;i++) A[i]=lower_bound(x.begin(),x.end(),A[i])-x.begin();
for(int i=0;i<N;i++) set_value(i,1);
for(auto &[a,b]: Q) {
if(b==-1) cout<<get_cnt(lower_bound(x.begin(),x.end(),a)-x.begin())<<'\n';
else {
set_value(a,-1);
if(a) set_value(a-1,-1);
if(a+1<N) set_value(a+1,-1);
A[a]=lower_bound(x.begin(),x.end(),b)-x.begin();
set_value(a,1);
if(a) set_value(a-1,1);
if(a+1<N) set_value(a+1,1);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
15 ms |
852 KB |
Output is correct |
5 |
Correct |
29 ms |
1244 KB |
Output is correct |
6 |
Correct |
43 ms |
1784 KB |
Output is correct |
7 |
Correct |
68 ms |
2288 KB |
Output is correct |
8 |
Correct |
86 ms |
2804 KB |
Output is correct |
9 |
Correct |
142 ms |
4464 KB |
Output is correct |
10 |
Correct |
140 ms |
4080 KB |
Output is correct |
11 |
Correct |
170 ms |
4976 KB |
Output is correct |
12 |
Correct |
188 ms |
5520 KB |
Output is correct |
13 |
Correct |
194 ms |
5616 KB |
Output is correct |
14 |
Correct |
188 ms |
5368 KB |
Output is correct |
15 |
Correct |
187 ms |
5364 KB |
Output is correct |
16 |
Correct |
193 ms |
5612 KB |
Output is correct |
17 |
Correct |
198 ms |
5668 KB |
Output is correct |
18 |
Correct |
193 ms |
5616 KB |
Output is correct |
19 |
Correct |
192 ms |
5612 KB |
Output is correct |
20 |
Correct |
195 ms |
5592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
632 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Correct |
15 ms |
852 KB |
Output is correct |
20 |
Correct |
29 ms |
1244 KB |
Output is correct |
21 |
Correct |
43 ms |
1784 KB |
Output is correct |
22 |
Correct |
68 ms |
2288 KB |
Output is correct |
23 |
Correct |
86 ms |
2804 KB |
Output is correct |
24 |
Correct |
142 ms |
4464 KB |
Output is correct |
25 |
Correct |
140 ms |
4080 KB |
Output is correct |
26 |
Correct |
170 ms |
4976 KB |
Output is correct |
27 |
Correct |
188 ms |
5520 KB |
Output is correct |
28 |
Correct |
194 ms |
5616 KB |
Output is correct |
29 |
Correct |
188 ms |
5368 KB |
Output is correct |
30 |
Correct |
187 ms |
5364 KB |
Output is correct |
31 |
Correct |
193 ms |
5612 KB |
Output is correct |
32 |
Correct |
198 ms |
5668 KB |
Output is correct |
33 |
Correct |
193 ms |
5616 KB |
Output is correct |
34 |
Correct |
192 ms |
5612 KB |
Output is correct |
35 |
Correct |
195 ms |
5592 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
4 ms |
376 KB |
Output is correct |
38 |
Correct |
4 ms |
504 KB |
Output is correct |
39 |
Correct |
17 ms |
760 KB |
Output is correct |
40 |
Correct |
31 ms |
1272 KB |
Output is correct |
41 |
Correct |
53 ms |
1780 KB |
Output is correct |
42 |
Correct |
77 ms |
2292 KB |
Output is correct |
43 |
Correct |
103 ms |
2956 KB |
Output is correct |
44 |
Correct |
192 ms |
4848 KB |
Output is correct |
45 |
Correct |
154 ms |
4068 KB |
Output is correct |
46 |
Correct |
178 ms |
4428 KB |
Output is correct |
47 |
Correct |
232 ms |
5784 KB |
Output is correct |
48 |
Correct |
235 ms |
5676 KB |
Output is correct |
49 |
Correct |
235 ms |
5788 KB |
Output is correct |
50 |
Correct |
233 ms |
5684 KB |
Output is correct |
51 |
Correct |
238 ms |
5736 KB |
Output is correct |
52 |
Correct |
240 ms |
5736 KB |
Output is correct |
53 |
Correct |
240 ms |
5828 KB |
Output is correct |
54 |
Correct |
238 ms |
5736 KB |
Output is correct |
55 |
Correct |
250 ms |
5804 KB |
Output is correct |