#include <bits/stdc++.h>
using namespace std;
const int Nmax = 4e5 + 5;
int n, q, m;
int tip[Nmax/2], val[Nmax/2], p[Nmax/2], a[Nmax/2];
vector<int> all;
class AIB
{
int ub(int x) { return (x&(-x)); }
int a[Nmax];
public:
void upd(int x, int y, int add)
{
for(; y; y-=ub(y)) a[y] += add;
for(--x; x; x-=ub(x)) a[x] -= add;
}
int query(int x)
{
int ans = 0;
for(; x<=m; x+=ub(x)) ans += a[x];
return ans;
}
} aib;
void cb(int &x)
{
x = lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
}
void init()
{
int i;
vector<int> s(m+2);
for(i=1; i<=n; ++i)
if(a[i] > a[i+1])
aib.upd(a[i+1] + 1, a[i], +1);
}
void update(int pos, int val)
{
if(pos-1 && a[pos-1] > a[pos])
aib.upd(a[pos] + 1, a[pos-1], -1);
if(a[pos] > a[pos+1])
aib.upd(a[pos+1] + 1, a[pos], -1);
a[pos] = val;
if(pos-1 && a[pos-1] > a[pos])
aib.upd(a[pos] + 1, a[pos-1], +1);
if(a[pos] > a[pos+1])
aib.upd(a[pos+1] + 1, a[pos], +1);
}
int main()
{
// freopen("input", "r", stdin);
cin.tie(0); cin.sync_with_stdio(false);
cin >> n >> q;
int i;
for(i=1; i<=n; ++i)
{
cin >> a[i];
all.push_back(a[i]);
}
for(i=1; i<=q; ++i)
{
cin >> tip[i] >> p[i];
if(tip[i] == 2)
{
cin >> val[i];
all.push_back(val[i]);
}
}
all.push_back(0);
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
m = all.size() + 1;
for(i=1; i<=n+1; ++i)
cb(a[i]);
for(i=1; i<=q; ++i)
if(tip[i] == 1) cb(p[i]);
else cb(val[i]);
init();
for(i=1; i<=q; ++i)
if(tip[i] == 1)
cout << aib.query(p[i]) << '\n';
else update(p[i], val[i]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 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 |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
12 ms |
1152 KB |
Output is correct |
5 |
Correct |
25 ms |
1920 KB |
Output is correct |
6 |
Correct |
36 ms |
2776 KB |
Output is correct |
7 |
Correct |
58 ms |
4036 KB |
Output is correct |
8 |
Correct |
73 ms |
4888 KB |
Output is correct |
9 |
Correct |
124 ms |
7708 KB |
Output is correct |
10 |
Correct |
119 ms |
7276 KB |
Output is correct |
11 |
Correct |
145 ms |
8804 KB |
Output is correct |
12 |
Correct |
167 ms |
9716 KB |
Output is correct |
13 |
Correct |
161 ms |
9696 KB |
Output is correct |
14 |
Correct |
175 ms |
9596 KB |
Output is correct |
15 |
Correct |
159 ms |
9580 KB |
Output is correct |
16 |
Correct |
166 ms |
9848 KB |
Output is correct |
17 |
Correct |
170 ms |
9824 KB |
Output is correct |
18 |
Correct |
166 ms |
9896 KB |
Output is correct |
19 |
Correct |
171 ms |
9824 KB |
Output is correct |
20 |
Correct |
172 ms |
9944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 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 |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
12 ms |
1152 KB |
Output is correct |
20 |
Correct |
25 ms |
1920 KB |
Output is correct |
21 |
Correct |
36 ms |
2776 KB |
Output is correct |
22 |
Correct |
58 ms |
4036 KB |
Output is correct |
23 |
Correct |
73 ms |
4888 KB |
Output is correct |
24 |
Correct |
124 ms |
7708 KB |
Output is correct |
25 |
Correct |
119 ms |
7276 KB |
Output is correct |
26 |
Correct |
145 ms |
8804 KB |
Output is correct |
27 |
Correct |
167 ms |
9716 KB |
Output is correct |
28 |
Correct |
161 ms |
9696 KB |
Output is correct |
29 |
Correct |
175 ms |
9596 KB |
Output is correct |
30 |
Correct |
159 ms |
9580 KB |
Output is correct |
31 |
Correct |
166 ms |
9848 KB |
Output is correct |
32 |
Correct |
170 ms |
9824 KB |
Output is correct |
33 |
Correct |
166 ms |
9896 KB |
Output is correct |
34 |
Correct |
171 ms |
9824 KB |
Output is correct |
35 |
Correct |
172 ms |
9944 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
3 ms |
512 KB |
Output is correct |
39 |
Correct |
14 ms |
1408 KB |
Output is correct |
40 |
Correct |
25 ms |
2176 KB |
Output is correct |
41 |
Correct |
44 ms |
3312 KB |
Output is correct |
42 |
Correct |
61 ms |
4464 KB |
Output is correct |
43 |
Correct |
85 ms |
5744 KB |
Output is correct |
44 |
Correct |
180 ms |
10096 KB |
Output is correct |
45 |
Correct |
127 ms |
8304 KB |
Output is correct |
46 |
Correct |
147 ms |
9200 KB |
Output is correct |
47 |
Correct |
203 ms |
11880 KB |
Output is correct |
48 |
Correct |
217 ms |
11880 KB |
Output is correct |
49 |
Correct |
193 ms |
11832 KB |
Output is correct |
50 |
Correct |
201 ms |
11752 KB |
Output is correct |
51 |
Correct |
192 ms |
12052 KB |
Output is correct |
52 |
Correct |
206 ms |
12000 KB |
Output is correct |
53 |
Correct |
193 ms |
12004 KB |
Output is correct |
54 |
Correct |
195 ms |
12148 KB |
Output is correct |
55 |
Correct |
197 ms |
12136 KB |
Output is correct |