#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
const int MAXN = 200005;
const int MAXQ = 200005;
const int MX = 524288;
struct BIT {
int d[MX*2];
void upd(int x, int r) {
for(x += MX; x; x /= 2) d[x] += r;
}
int get(int s, int e) {
int r = 0; for(s += MX, e += MX; s <= e; s /= 2, e /= 2) {
if(s&1) r += d[s++]; if(~e&1) r += d[e--];
} return r;
}
int get(int x) { return get(x, MX-1); }
} segV, segE;
int A[MAXN];
int B[MAXQ], C[MAXQ], D[MAXQ];
int N, Q;
int main() {
ios::sync_with_stdio(false);
cin >> N >> Q;
for(int i = 1; i <= N; i++) cin >> A[i];
for(int i = 1; i <= Q; i++) {
cin >> B[i] >> C[i];
if(2 == B[i]) cin >> D[i];
}
{
vector<int> V;
for(int i = 1; i <= N; i++) V.pb(A[i]);
for(int i = 1; i <= Q; i++)
V.pb(1 == B[i] ? C[i] : D[i]);
sorv(V); univ(V);
for(int i = 1; i <= N; i++)
A[i] = (int)(lower_bound(allv(V), A[i]) - V.begin()) + 1;
for(int i = 1; i <= Q; i++) {
if(1 == B[i])
C[i] = (int)(lower_bound(allv(V), C[i]) - V.begin()) + 1;
else
D[i] = (int)(lower_bound(allv(V), D[i]) - V.begin()) + 1;
}
}
for(int i = 1; i <= N; i++) {
segV.upd(A[i], 1);
if(1 < i && A[i] <= A[i-1]) segE.upd(A[i], 1);
if(i < N && A[i] < A[i+1]) segE.upd(A[i], 1);
}
for(int qi = 1; qi <= Q; qi++) {
if(1 == B[qi]) {
printf("%d\n", segV.get(C[qi]) - segE.get(C[qi]));
} else {
int x = C[qi], y = D[qi];
{
segV.upd(A[x], -1);
if(1 < x && A[x] <= A[x-1]) segE.upd(A[x], -1);
if(x < N && A[x] < A[x+1]) segE.upd(A[x], -1);
if(1 < x && A[x-1] < A[x]) segE.upd(A[x-1], -1);
if(x < N && A[x+1] <= A[x]) segE.upd(A[x+1], -1);
}
{
A[x] = y;
segV.upd(y, 1);
if(1 < x && A[x] <= A[x-1]) segE.upd(A[x], 1);
if(x < N && A[x] < A[x+1]) segE.upd(A[x], 1);
if(1 < x && A[x-1] < A[x]) segE.upd(A[x-1], 1);
if(x < N && A[x+1] <= A[x]) segE.upd(A[x+1], 1);
}
}
}
return 0;
}
Compilation message
employment.cpp: In member function 'int BIT::get(int, int)':
employment.cpp:35:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(s&1) r += d[s++]; if(~e&1) r += d[e--];
^~
employment.cpp:35:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(s&1) r += d[s++]; if(~e&1) r += d[e--];
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
20 ms |
1280 KB |
Output is correct |
5 |
Correct |
38 ms |
2044 KB |
Output is correct |
6 |
Correct |
79 ms |
3052 KB |
Output is correct |
7 |
Correct |
96 ms |
4112 KB |
Output is correct |
8 |
Correct |
120 ms |
5128 KB |
Output is correct |
9 |
Correct |
230 ms |
8336 KB |
Output is correct |
10 |
Correct |
196 ms |
7268 KB |
Output is correct |
11 |
Correct |
253 ms |
9208 KB |
Output is correct |
12 |
Correct |
291 ms |
10144 KB |
Output is correct |
13 |
Correct |
297 ms |
10128 KB |
Output is correct |
14 |
Correct |
288 ms |
9996 KB |
Output is correct |
15 |
Correct |
301 ms |
10088 KB |
Output is correct |
16 |
Correct |
331 ms |
10296 KB |
Output is correct |
17 |
Correct |
294 ms |
10296 KB |
Output is correct |
18 |
Correct |
324 ms |
10300 KB |
Output is correct |
19 |
Correct |
300 ms |
10304 KB |
Output is correct |
20 |
Correct |
286 ms |
10300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
640 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Correct |
20 ms |
1280 KB |
Output is correct |
20 |
Correct |
38 ms |
2044 KB |
Output is correct |
21 |
Correct |
79 ms |
3052 KB |
Output is correct |
22 |
Correct |
96 ms |
4112 KB |
Output is correct |
23 |
Correct |
120 ms |
5128 KB |
Output is correct |
24 |
Correct |
230 ms |
8336 KB |
Output is correct |
25 |
Correct |
196 ms |
7268 KB |
Output is correct |
26 |
Correct |
253 ms |
9208 KB |
Output is correct |
27 |
Correct |
291 ms |
10144 KB |
Output is correct |
28 |
Correct |
297 ms |
10128 KB |
Output is correct |
29 |
Correct |
288 ms |
9996 KB |
Output is correct |
30 |
Correct |
301 ms |
10088 KB |
Output is correct |
31 |
Correct |
331 ms |
10296 KB |
Output is correct |
32 |
Correct |
294 ms |
10296 KB |
Output is correct |
33 |
Correct |
324 ms |
10300 KB |
Output is correct |
34 |
Correct |
300 ms |
10304 KB |
Output is correct |
35 |
Correct |
286 ms |
10300 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
4 ms |
640 KB |
Output is correct |
38 |
Correct |
3 ms |
640 KB |
Output is correct |
39 |
Correct |
27 ms |
1408 KB |
Output is correct |
40 |
Correct |
39 ms |
1948 KB |
Output is correct |
41 |
Correct |
71 ms |
3004 KB |
Output is correct |
42 |
Correct |
96 ms |
3920 KB |
Output is correct |
43 |
Correct |
119 ms |
5088 KB |
Output is correct |
44 |
Correct |
277 ms |
8648 KB |
Output is correct |
45 |
Correct |
217 ms |
7340 KB |
Output is correct |
46 |
Correct |
233 ms |
8000 KB |
Output is correct |
47 |
Correct |
304 ms |
10212 KB |
Output is correct |
48 |
Correct |
338 ms |
10432 KB |
Output is correct |
49 |
Correct |
299 ms |
10304 KB |
Output is correct |
50 |
Correct |
319 ms |
10220 KB |
Output is correct |
51 |
Correct |
319 ms |
10616 KB |
Output is correct |
52 |
Correct |
315 ms |
10572 KB |
Output is correct |
53 |
Correct |
311 ms |
10428 KB |
Output is correct |
54 |
Correct |
342 ms |
10520 KB |
Output is correct |
55 |
Correct |
300 ms |
10556 KB |
Output is correct |