#include <bits/stdc++.h>
#define int long long
using namespace std;
int aint[8000 * 4 + 5];
int ain2[50000 * 4 + 2][102];
int lazy[50000 * 4 + 2][102];
const int INF = 1e9;
void update(int nod, int st, int dr, int poz, int val)
{
if(st == dr)
{
aint[nod] += val;
return;
}
int mij = (st + dr) / 2;
if(poz <= mij) update(nod * 2, st, mij, poz, val);
else update(nod * 2 + 1, mij + 1, dr, poz, val);
aint[nod] = max(aint[nod * 2], aint[nod * 2 + 1]);
}
void propagate(int nod, int id)
{
ain2[nod * 2][id] += lazy[nod][id];
ain2[nod * 2 + 1][id] += lazy[nod][id];
lazy[nod * 2][id] += lazy[nod][id];
lazy[nod * 2 + 1][id] += lazy[nod][id];
lazy[nod][id] = 0;
}
void update2(int nod, int st, int dr, int le, int ri, int val, int id)
{
if(le > ri)
return;
if(st == le && dr == ri)
{
ain2[nod][id] += val;
lazy[nod][id] += val;
return;
}
propagate(nod, id);
int mij = (st + dr) / 2;
update2(nod * 2, st, mij, le, min(ri, mij), val, id);
update2(nod * 2 + 1, mij + 1, dr, max(le, mij + 1), ri, val, id);
ain2[nod][id] = max(ain2[nod * 2][id], ain2[nod * 2 + 1][id]);
}
vector<int32_t> countScans(vector<int32_t> a, vector<int32_t> x, vector<int32_t> v)
{
int n = a.size();
int q = x.size();
if(n <= 8000 && q <= 8000)
{
int rez = 0;
for(int i = 0; i < n; i++)
for(int j = i - 1; j >= 0; j--)
if(a[j] > a[i])
update(1, 1, n, i + 1, 1);
vector<int32_t> fin;
for(int i = 0; i < q; i++)
{
//cout<<rez<<" zzzz\n";
for(int j = x[i] + 1; j < n; j++)
{
if(a[x[i]] > a[j])
update(1, 1, n, j + 1, -1);
if(v[i] > a[j])
update(1, 1, n, j + 1, 1);
}
for(int j = x[i] - 1; j >= 0; j--)
{
if(a[j] > a[x[i]])
update(1, 1, n, x[i] + 1, -1);
if(a[j] > v[i])
update(1, 1, n, x[i] + 1, 1);
}
a[x[i]] = v[i];
fin.push_back(aint[1]);
}
return fin;
}
else
{
for(int i = 1; i <= 100; i++)
update2(1, 1, n, 1, n, -INF, i);
for(int i = 0; i < n; i++)
{
update2(1, 1, n, i + 1, i + 1, INF, a[i]);
for(int val = a[i] - 1; val >= 1; val--)
{
update2(1, 1, n, i + 2, n, 1, val);
}
}
vector<int32_t> fin;
for(int i = 0; i < q; i++)
{
update2(1, 1, n, x[i] + 1, x[i] + 1, -INF, a[x[i]]);
update2(1, 1, n, x[i] + 1, x[i] + 1, INF, v[i]);
for(int val = a[x[i]] - 1; val >= 1; val--)
{
update2(1, 1, n, x[i] + 2, n, -1, val);
}
for(int val = v[i] - 1; val >= 1; val--)
{
update2(1, 1, n, x[i] + 2, n, 1, val);
}
int rez = 0;
for(int j = 1; j <= 100; j++)
rez = max(rez, ain2[1][j]);
fin.push_back(rez);
a[x[i]] = v[i];
}
return fin;
}
}
/*int main()
{
int n;
cin>>n;
vector<int> read;
for(int i = 1; i <= n; i++)
{
int a;
cin>>a;
read.push_back(a);
}
vector<int> q1, q2;
int q;
cin>>q;
for(int i = 1; i <= q; i++)
{
int a, b;
cin>>a>>b;
q1.push_back(a);
q2.push_back(b);
}
vector<int> rez = countScans(read, q1, q2);
for(auto it : rez)
cout<<it<<'\n';
return 0;
}*/
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:60:13: warning: unused variable 'rez' [-Wunused-variable]
60 | int rez = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
348 KB |
Output is correct |
2 |
Correct |
39 ms |
460 KB |
Output is correct |
3 |
Correct |
269 ms |
516 KB |
Output is correct |
4 |
Correct |
271 ms |
592 KB |
Output is correct |
5 |
Correct |
138 ms |
520 KB |
Output is correct |
6 |
Correct |
132 ms |
508 KB |
Output is correct |
7 |
Correct |
141 ms |
512 KB |
Output is correct |
8 |
Correct |
144 ms |
760 KB |
Output is correct |
9 |
Correct |
139 ms |
348 KB |
Output is correct |
10 |
Correct |
322 ms |
344 KB |
Output is correct |
11 |
Correct |
328 ms |
348 KB |
Output is correct |
12 |
Correct |
342 ms |
344 KB |
Output is correct |
13 |
Correct |
325 ms |
504 KB |
Output is correct |
14 |
Correct |
298 ms |
516 KB |
Output is correct |
15 |
Correct |
291 ms |
516 KB |
Output is correct |
16 |
Correct |
251 ms |
516 KB |
Output is correct |
17 |
Correct |
241 ms |
520 KB |
Output is correct |
18 |
Correct |
241 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
348 KB |
Output is correct |
2 |
Correct |
39 ms |
460 KB |
Output is correct |
3 |
Correct |
269 ms |
516 KB |
Output is correct |
4 |
Correct |
271 ms |
592 KB |
Output is correct |
5 |
Correct |
138 ms |
520 KB |
Output is correct |
6 |
Correct |
132 ms |
508 KB |
Output is correct |
7 |
Correct |
141 ms |
512 KB |
Output is correct |
8 |
Correct |
144 ms |
760 KB |
Output is correct |
9 |
Correct |
139 ms |
348 KB |
Output is correct |
10 |
Correct |
322 ms |
344 KB |
Output is correct |
11 |
Correct |
328 ms |
348 KB |
Output is correct |
12 |
Correct |
342 ms |
344 KB |
Output is correct |
13 |
Correct |
325 ms |
504 KB |
Output is correct |
14 |
Correct |
298 ms |
516 KB |
Output is correct |
15 |
Correct |
291 ms |
516 KB |
Output is correct |
16 |
Correct |
251 ms |
516 KB |
Output is correct |
17 |
Correct |
241 ms |
520 KB |
Output is correct |
18 |
Correct |
241 ms |
512 KB |
Output is correct |
19 |
Correct |
3850 ms |
1000 KB |
Output is correct |
20 |
Correct |
4950 ms |
600 KB |
Output is correct |
21 |
Correct |
2580 ms |
800 KB |
Output is correct |
22 |
Correct |
2581 ms |
1012 KB |
Output is correct |
23 |
Correct |
6199 ms |
1032 KB |
Output is correct |
24 |
Correct |
6341 ms |
796 KB |
Output is correct |
25 |
Correct |
5422 ms |
1056 KB |
Output is correct |
26 |
Correct |
5454 ms |
1032 KB |
Output is correct |
27 |
Correct |
4740 ms |
1052 KB |
Output is correct |
28 |
Correct |
4795 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
109652 KB |
Output is correct |
2 |
Correct |
959 ms |
212848 KB |
Output is correct |
3 |
Correct |
1681 ms |
213600 KB |
Output is correct |
4 |
Correct |
1638 ms |
213444 KB |
Output is correct |
5 |
Correct |
2105 ms |
213456 KB |
Output is correct |
6 |
Correct |
2061 ms |
213444 KB |
Output is correct |
7 |
Correct |
2347 ms |
213868 KB |
Output is correct |
8 |
Correct |
2268 ms |
213508 KB |
Output is correct |
9 |
Correct |
2388 ms |
213592 KB |
Output is correct |
10 |
Correct |
2491 ms |
213692 KB |
Output is correct |
11 |
Correct |
2547 ms |
213456 KB |
Output is correct |
12 |
Correct |
2498 ms |
213588 KB |
Output is correct |
13 |
Correct |
2356 ms |
213584 KB |
Output is correct |
14 |
Correct |
2311 ms |
213628 KB |
Output is correct |
15 |
Correct |
2256 ms |
213724 KB |
Output is correct |
16 |
Correct |
1990 ms |
213452 KB |
Output is correct |
17 |
Correct |
1984 ms |
213428 KB |
Output is correct |
18 |
Correct |
2035 ms |
213440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
348 KB |
Output is correct |
2 |
Correct |
39 ms |
460 KB |
Output is correct |
3 |
Correct |
269 ms |
516 KB |
Output is correct |
4 |
Correct |
271 ms |
592 KB |
Output is correct |
5 |
Correct |
138 ms |
520 KB |
Output is correct |
6 |
Correct |
132 ms |
508 KB |
Output is correct |
7 |
Correct |
141 ms |
512 KB |
Output is correct |
8 |
Correct |
144 ms |
760 KB |
Output is correct |
9 |
Correct |
139 ms |
348 KB |
Output is correct |
10 |
Correct |
322 ms |
344 KB |
Output is correct |
11 |
Correct |
328 ms |
348 KB |
Output is correct |
12 |
Correct |
342 ms |
344 KB |
Output is correct |
13 |
Correct |
325 ms |
504 KB |
Output is correct |
14 |
Correct |
298 ms |
516 KB |
Output is correct |
15 |
Correct |
291 ms |
516 KB |
Output is correct |
16 |
Correct |
251 ms |
516 KB |
Output is correct |
17 |
Correct |
241 ms |
520 KB |
Output is correct |
18 |
Correct |
241 ms |
512 KB |
Output is correct |
19 |
Correct |
3850 ms |
1000 KB |
Output is correct |
20 |
Correct |
4950 ms |
600 KB |
Output is correct |
21 |
Correct |
2580 ms |
800 KB |
Output is correct |
22 |
Correct |
2581 ms |
1012 KB |
Output is correct |
23 |
Correct |
6199 ms |
1032 KB |
Output is correct |
24 |
Correct |
6341 ms |
796 KB |
Output is correct |
25 |
Correct |
5422 ms |
1056 KB |
Output is correct |
26 |
Correct |
5454 ms |
1032 KB |
Output is correct |
27 |
Correct |
4740 ms |
1052 KB |
Output is correct |
28 |
Correct |
4795 ms |
852 KB |
Output is correct |
29 |
Correct |
300 ms |
109652 KB |
Output is correct |
30 |
Correct |
959 ms |
212848 KB |
Output is correct |
31 |
Correct |
1681 ms |
213600 KB |
Output is correct |
32 |
Correct |
1638 ms |
213444 KB |
Output is correct |
33 |
Correct |
2105 ms |
213456 KB |
Output is correct |
34 |
Correct |
2061 ms |
213444 KB |
Output is correct |
35 |
Correct |
2347 ms |
213868 KB |
Output is correct |
36 |
Correct |
2268 ms |
213508 KB |
Output is correct |
37 |
Correct |
2388 ms |
213592 KB |
Output is correct |
38 |
Correct |
2491 ms |
213692 KB |
Output is correct |
39 |
Correct |
2547 ms |
213456 KB |
Output is correct |
40 |
Correct |
2498 ms |
213588 KB |
Output is correct |
41 |
Correct |
2356 ms |
213584 KB |
Output is correct |
42 |
Correct |
2311 ms |
213628 KB |
Output is correct |
43 |
Correct |
2256 ms |
213724 KB |
Output is correct |
44 |
Correct |
1990 ms |
213452 KB |
Output is correct |
45 |
Correct |
1984 ms |
213428 KB |
Output is correct |
46 |
Correct |
2035 ms |
213440 KB |
Output is correct |
47 |
Runtime error |
59 ms |
11604 KB |
Execution killed with signal 11 |
48 |
Halted |
0 ms |
0 KB |
- |