#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
const int MAXVAL = 8e5;
const int INF = 2147483647;
struct Data { int t, a, b; };
int N, Q, A[MAXN+10];
Data B[MAXN+10];
int tree[4*MAXVAL+10];
vector<int> comp, comp2;
int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin()+1; }
int getcomp2(int x) { return *lower_bound(comp2.begin(), comp2.end(), x); }
void update(int node, int tl, int tr, int l, int r, int val)
{
if(l>r) return;
if(tr<l || r<tl) return;
if(l<=tl && tr<=r)
{
tree[node]+=val;
return;
}
int mid=tl+tr>>1;
update(node*2, tl, mid, l, r, val);
update(node*2+1, mid+1, tr, l, r, val);
}
int query(int node, int tl, int tr, int pos)
{
if(tl==tr) return tree[node];
int mid=tl+tr>>1;
if(pos<=mid) return tree[node]+query(node*2, tl, mid, pos);
else return tree[node]+query(node*2+1, mid+1, tr, pos);
}
int main()
{
int i, j;
scanf("%d%d", &N, &Q);
for(i=1; i<=N; i++) scanf("%d", &A[i]), comp.push_back(A[i]), comp.push_back(A[i]+1), comp2.push_back(A[i]);
for(i=1; i<=Q; i++)
{
scanf("%d", &B[i].t);
if(B[i].t==1) scanf("%d", &B[i].a);
else scanf("%d%d", &B[i].a, &B[i].b), comp.push_back(B[i].b), comp.push_back(B[i].b+1), comp2.push_back(B[i].b);
}
comp.push_back(INF); comp.push_back(1); comp2.push_back(INF); comp2.push_back(0);
sort(comp.begin(), comp.end()); sort(comp2.begin(), comp2.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end()); comp2.erase(unique(comp2.begin(), comp2.end()), comp2.end());
for(i=1; i<=N+1; i++)
{
int a=min(A[i], A[i-1])+1, b=max(A[i], A[i-1]);
update(1, 1, comp.size(), getcomp(a), getcomp(b), 1);
}
for(i=1; i<=Q; i++)
{
if(B[i].t==1) printf("%d\n", query(1, 1, comp.size(), getcomp(getcomp2(B[i].a)))/2);
else
{
int a, b;
a=min(A[B[i].a], A[B[i].a-1])+1, b=max(A[B[i].a], A[B[i].a-1]);
update(1, 1, comp.size(), getcomp(a), getcomp(b), -1);
a=min(A[B[i].a], A[B[i].a+1])+1, b=max(A[B[i].a], A[B[i].a+1]);
update(1, 1, comp.size(), getcomp(a), getcomp(b), -1);
A[B[i].a]=B[i].b;
a=min(A[B[i].a], A[B[i].a-1])+1, b=max(A[B[i].a], A[B[i].a-1]);
update(1, 1, comp.size(), getcomp(a), getcomp(b), 1);
a=min(A[B[i].a], A[B[i].a+1])+1, b=max(A[B[i].a], A[B[i].a+1]);
update(1, 1, comp.size(), getcomp(a), getcomp(b), 1);
}
}
}
Compilation message
employment.cpp: In function 'void update(int, int, int, int, int, int)':
employment.cpp:31:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
employment.cpp: In function 'int query(int, int, int, int)':
employment.cpp:39:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
employment.cpp: In function 'int main()':
employment.cpp:46:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
employment.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &Q);
~~~~~^~~~~~~~~~~~~~~~
employment.cpp:49:89: 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]), comp.push_back(A[i]), comp.push_back(A[i]+1), comp2.push_back(A[i]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
employment.cpp:52:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &B[i].t);
~~~~~^~~~~~~~~~~~~~~
employment.cpp:53:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
if(B[i].t==1) scanf("%d", &B[i].a);
~~~~~^~~~~~~~~~~~~~~
employment.cpp:54:92: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
else scanf("%d%d", &B[i].a, &B[i].b), comp.push_back(B[i].b), comp.push_back(B[i].b+1), comp2.push_back(B[i].b);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
372 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
484 KB |
Output is correct |
10 |
Correct |
7 ms |
504 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
7 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
504 KB |
Output is correct |
14 |
Correct |
7 ms |
504 KB |
Output is correct |
15 |
Correct |
7 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
6 ms |
504 KB |
Output is correct |
3 |
Correct |
6 ms |
504 KB |
Output is correct |
4 |
Correct |
27 ms |
1144 KB |
Output is correct |
5 |
Correct |
64 ms |
2668 KB |
Output is correct |
6 |
Correct |
92 ms |
3312 KB |
Output is correct |
7 |
Correct |
155 ms |
5480 KB |
Output is correct |
8 |
Correct |
201 ms |
6124 KB |
Output is correct |
9 |
Correct |
322 ms |
8044 KB |
Output is correct |
10 |
Correct |
345 ms |
10308 KB |
Output is correct |
11 |
Correct |
397 ms |
11368 KB |
Output is correct |
12 |
Correct |
462 ms |
12124 KB |
Output is correct |
13 |
Correct |
454 ms |
12124 KB |
Output is correct |
14 |
Correct |
447 ms |
11912 KB |
Output is correct |
15 |
Correct |
447 ms |
12004 KB |
Output is correct |
16 |
Correct |
472 ms |
12064 KB |
Output is correct |
17 |
Correct |
459 ms |
12140 KB |
Output is correct |
18 |
Correct |
465 ms |
12280 KB |
Output is correct |
19 |
Correct |
468 ms |
12264 KB |
Output is correct |
20 |
Correct |
454 ms |
12104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
372 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
484 KB |
Output is correct |
10 |
Correct |
7 ms |
504 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
7 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
504 KB |
Output is correct |
14 |
Correct |
7 ms |
504 KB |
Output is correct |
15 |
Correct |
7 ms |
504 KB |
Output is correct |
16 |
Correct |
4 ms |
504 KB |
Output is correct |
17 |
Correct |
6 ms |
504 KB |
Output is correct |
18 |
Correct |
6 ms |
504 KB |
Output is correct |
19 |
Correct |
27 ms |
1144 KB |
Output is correct |
20 |
Correct |
64 ms |
2668 KB |
Output is correct |
21 |
Correct |
92 ms |
3312 KB |
Output is correct |
22 |
Correct |
155 ms |
5480 KB |
Output is correct |
23 |
Correct |
201 ms |
6124 KB |
Output is correct |
24 |
Correct |
322 ms |
8044 KB |
Output is correct |
25 |
Correct |
345 ms |
10308 KB |
Output is correct |
26 |
Correct |
397 ms |
11368 KB |
Output is correct |
27 |
Correct |
462 ms |
12124 KB |
Output is correct |
28 |
Correct |
454 ms |
12124 KB |
Output is correct |
29 |
Correct |
447 ms |
11912 KB |
Output is correct |
30 |
Correct |
447 ms |
12004 KB |
Output is correct |
31 |
Correct |
472 ms |
12064 KB |
Output is correct |
32 |
Correct |
459 ms |
12140 KB |
Output is correct |
33 |
Correct |
465 ms |
12280 KB |
Output is correct |
34 |
Correct |
468 ms |
12264 KB |
Output is correct |
35 |
Correct |
454 ms |
12104 KB |
Output is correct |
36 |
Correct |
5 ms |
504 KB |
Output is correct |
37 |
Correct |
7 ms |
504 KB |
Output is correct |
38 |
Correct |
9 ms |
632 KB |
Output is correct |
39 |
Correct |
51 ms |
1908 KB |
Output is correct |
40 |
Correct |
94 ms |
3312 KB |
Output is correct |
41 |
Correct |
171 ms |
5864 KB |
Output is correct |
42 |
Correct |
239 ms |
7200 KB |
Output is correct |
43 |
Correct |
335 ms |
11072 KB |
Output is correct |
44 |
Correct |
643 ms |
15460 KB |
Output is correct |
45 |
Correct |
542 ms |
13768 KB |
Output is correct |
46 |
Correct |
573 ms |
14564 KB |
Output is correct |
47 |
Correct |
788 ms |
22536 KB |
Output is correct |
48 |
Correct |
834 ms |
22656 KB |
Output is correct |
49 |
Correct |
812 ms |
22748 KB |
Output is correct |
50 |
Correct |
783 ms |
22364 KB |
Output is correct |
51 |
Correct |
808 ms |
22748 KB |
Output is correct |
52 |
Correct |
835 ms |
22912 KB |
Output is correct |
53 |
Correct |
816 ms |
22812 KB |
Output is correct |
54 |
Correct |
822 ms |
22876 KB |
Output is correct |
55 |
Correct |
835 ms |
22812 KB |
Output is correct |