#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 8e5;
int N, M, S, A[MAXN+10];
struct Query
{
int t, a, b;
};
Query B[MAXN+10];
vector<int> comp;
int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin()+1; }
int tree[MAXN*4+10];
void update(int node, int tl, int tr, int l, int r, int k)
{
if(l>r) return;
if(r<tl || tr<l) return;
if(l<=tl && tr<=r) { tree[node]+=k; return; }
int mid=tl+tr>>1;
update(node*2, tl, mid, l, r, k);
update(node*2+1, mid+1, tr, l, r, k);
}
int query(int node, int tl, int tr, int p)
{
if(tl==tr) return tree[node];
int mid=tl+tr>>1;
if(p<=mid) return query(node*2, tl, mid, p)+tree[node];
else return query(node*2+1, mid+1, tr, p)+tree[node];
}
int main()
{
int i, j;
scanf("%d%d", &N, &M);
for(i=1; i<=N; i++) scanf("%d", &A[i]);
for(i=1; i<=M; i++)
{
int t=0, a=0, b=0;
scanf("%d", &t);
if(t==1) scanf("%d", &a), comp.push_back(a);
else scanf("%d%d", &a, &b), comp.push_back(b), comp.push_back(b+1);
B[i].t=t; B[i].a=a; B[i].b=b;
}
comp.push_back(0);
comp.push_back(1);
for(i=1; i<=N; i++)
{
comp.push_back(A[i]);
comp.push_back(A[i]+1);
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
S=comp.size();
for(i=1; i<=N+1; i++)
{
int a=getcomp(min(A[i-1], A[i])+1), b=getcomp(max(A[i-1], A[i]));
update(1, 1, S, a, b, 1);
}
for(i=1; i<=M; i++)
{
int t=B[i].t, a=B[i].a, b=B[i].b;
if(t==1) printf("%d\n", query(1, 1, S, getcomp(a))/2);
else
{
int p, q;
p=getcomp(min(A[a-1], A[a])+1), q=getcomp(max(A[a-1], A[a]));
update(1, 1, S, p, q, -1);
p=getcomp(min(A[a+1], A[a])+1), q=getcomp(max(A[a+1], A[a]));
update(1, 1, S, p, q, -1);
A[a]=b;
p=getcomp(min(A[a-1], A[a])+1), q=getcomp(max(A[a-1], A[a]));
update(1, 1, S, p, q, 1);
p=getcomp(min(A[a+1], A[a])+1), q=getcomp(max(A[a+1], A[a]));
update(1, 1, S, p, q, 1);
}
}
}
Compilation message
employment.cpp: In function 'void update(int, int, int, int, int, int)':
employment.cpp:27:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
employment.cpp: In function 'int query(int, int, int, int)':
employment.cpp:34:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
employment.cpp: In function 'int main()':
employment.cpp:41:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
employment.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
employment.cpp:44:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
employment.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &t);
~~~~~^~~~~~~~~~
employment.cpp:50:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
if(t==1) scanf("%d", &a), comp.push_back(a);
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
employment.cpp:51:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
else scanf("%d%d", &a, &b), comp.push_back(b), comp.push_back(b+1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
512 KB |
Output is correct |
4 |
Correct |
26 ms |
1908 KB |
Output is correct |
5 |
Correct |
55 ms |
3184 KB |
Output is correct |
6 |
Correct |
86 ms |
5228 KB |
Output is correct |
7 |
Correct |
139 ms |
6696 KB |
Output is correct |
8 |
Correct |
178 ms |
9696 KB |
Output is correct |
9 |
Correct |
304 ms |
13284 KB |
Output is correct |
10 |
Correct |
348 ms |
12120 KB |
Output is correct |
11 |
Correct |
372 ms |
14436 KB |
Output is correct |
12 |
Correct |
405 ms |
19420 KB |
Output is correct |
13 |
Correct |
422 ms |
19564 KB |
Output is correct |
14 |
Correct |
402 ms |
19292 KB |
Output is correct |
15 |
Correct |
411 ms |
19276 KB |
Output is correct |
16 |
Correct |
427 ms |
19676 KB |
Output is correct |
17 |
Correct |
421 ms |
19548 KB |
Output is correct |
18 |
Correct |
424 ms |
19676 KB |
Output is correct |
19 |
Correct |
422 ms |
19548 KB |
Output is correct |
20 |
Correct |
423 ms |
19812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
19 |
Correct |
26 ms |
1908 KB |
Output is correct |
20 |
Correct |
55 ms |
3184 KB |
Output is correct |
21 |
Correct |
86 ms |
5228 KB |
Output is correct |
22 |
Correct |
139 ms |
6696 KB |
Output is correct |
23 |
Correct |
178 ms |
9696 KB |
Output is correct |
24 |
Correct |
304 ms |
13284 KB |
Output is correct |
25 |
Correct |
348 ms |
12120 KB |
Output is correct |
26 |
Correct |
372 ms |
14436 KB |
Output is correct |
27 |
Correct |
405 ms |
19420 KB |
Output is correct |
28 |
Correct |
422 ms |
19564 KB |
Output is correct |
29 |
Correct |
402 ms |
19292 KB |
Output is correct |
30 |
Correct |
411 ms |
19276 KB |
Output is correct |
31 |
Correct |
427 ms |
19676 KB |
Output is correct |
32 |
Correct |
421 ms |
19548 KB |
Output is correct |
33 |
Correct |
424 ms |
19676 KB |
Output is correct |
34 |
Correct |
422 ms |
19548 KB |
Output is correct |
35 |
Correct |
423 ms |
19812 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
5 ms |
512 KB |
Output is correct |
38 |
Correct |
6 ms |
640 KB |
Output is correct |
39 |
Correct |
43 ms |
2160 KB |
Output is correct |
40 |
Correct |
86 ms |
3184 KB |
Output is correct |
41 |
Correct |
144 ms |
5356 KB |
Output is correct |
42 |
Correct |
203 ms |
6380 KB |
Output is correct |
43 |
Correct |
298 ms |
9700 KB |
Output is correct |
44 |
Correct |
568 ms |
18144 KB |
Output is correct |
45 |
Correct |
449 ms |
12260 KB |
Output is correct |
46 |
Correct |
507 ms |
17192 KB |
Output is correct |
47 |
Correct |
694 ms |
19936 KB |
Output is correct |
48 |
Correct |
708 ms |
20016 KB |
Output is correct |
49 |
Correct |
709 ms |
19932 KB |
Output is correct |
50 |
Correct |
688 ms |
20060 KB |
Output is correct |
51 |
Correct |
751 ms |
20176 KB |
Output is correct |
52 |
Correct |
725 ms |
20188 KB |
Output is correct |
53 |
Correct |
724 ms |
20212 KB |
Output is correct |
54 |
Correct |
717 ms |
20156 KB |
Output is correct |
55 |
Correct |
731 ms |
20080 KB |
Output is correct |