#include "bubblesort2.h"
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) int(x.size())
struct sdata
{
set<int> inds;
int currans;
int count;
};
sdata combine(sdata X, sdata Y)
{
sdata res;
res.count = X.count + Y.count;
res.currans = max(X.currans, Y.currans - X.count);
return res;
}
int N, Q;
vi A;
struct segtree
{
int Z;
vi l, r;
vector<sdata> s;
void build(int i, int L, int R)
{
l[i] = L;
r[i] = R;
if(L == R)
{
s[i].currans = -3'000'000;
s[i].count = 0;
}
else
{
int m = (L+R)/2;
build(2*i, L, m);
build(2*i+1, m+1, R);
s[i] = combine(s[2*i], s[2*i+1]);
}
// cerr << L << ' ' << R << " : " << s[i].currans << ' ' << s[i].count << '\n';
}
segtree(int K)
{
Z = 4*K;
l = r = vi(1+Z);
s = vector<sdata>(1+Z);
build(1, 0, K-1);
}
void insert(int i, int p, int id)
{
if(l[i] == r[i])
{
s[i].inds.insert(id);
s[i].currans = max(s[i].currans, id);
s[i].count++;
}
else
{
if(p <= (l[i]+r[i])/2)
insert(2*i, p, id);
else
insert(2*i+1, p, id);
s[i] = combine(s[2*i], s[2*i+1]);
}
// cerr << l[i] << ' ' << r[i] << " : " << s[i].currans << ' ' << s[i].count << '\n';
}
void erase(int i, int p, int id)
{
if(l[i] == r[i])
{
s[i].inds.erase(id);
s[i].count--;
s[i].currans = (s[i].inds.empty() ? -3'000'000 : *s[i].inds.rbegin());
}
else
{
if(p <= (l[i]+r[i])/2)
erase(2*i, p, id);
else
erase(2*i+1, p, id);
s[i] = combine(s[2*i], s[2*i+1]);
}
// cerr << l[i] << ' ' << r[i] << " : " << s[i].currans << ' ' << s[i].count << '\n';
}
};
vi countScans(vi A_, vi X, vi V)
{
A = A_;
N = sz(A);
Q = sz(X);
map<pii, int> vals;
for(int i = 0; i < N; i++)
vals[{A[i], i}] = 0;
for(int j = 0; j < Q; j++)
vals[{V[j], X[j]}] = 0;
int ct = -1;
for(auto& z : vals)
{
z.second = ++ct;
cerr << z.first.first << " - " << z.second << '\n';
}
// cerr << "values # = " << sz(vals) << '\n';
vi answer(Q);
segtree S(N+Q);
for(int i = 0; i < N; i++)
{
// cerr << "\n\n\n";
// cerr << "i = " << i << '\n';
// cerr << "insert " << i << " at " << vals[{A[i], i}] << '\n';
S.insert(1, vals[{A[i], i}], i);
}
// cerr << "basic ans = " << S.s[1].currans << '\n';
for(int j = 0; j < Q; j++)
{
// cerr << "\n\n\n";
// cerr << "j = " << j << '\n';
S.erase(1, vals[{A[X[j]], X[j]}], X[j]);
A[X[j]] = V[j];
S.insert(1, vals[{A[X[j]], X[j]}], X[j]);
// cerr << "new array = ";
// for(int i = 0; i < N; i++) cerr << A[i] << ' ';
// cerr << '\n';
answer[j] = S.s[1].currans;
}
return answer;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
724 KB |
Output is correct |
2 |
Correct |
14 ms |
852 KB |
Output is correct |
3 |
Correct |
27 ms |
1808 KB |
Output is correct |
4 |
Correct |
25 ms |
1756 KB |
Output is correct |
5 |
Correct |
31 ms |
1740 KB |
Output is correct |
6 |
Correct |
27 ms |
1724 KB |
Output is correct |
7 |
Correct |
27 ms |
1708 KB |
Output is correct |
8 |
Correct |
29 ms |
1740 KB |
Output is correct |
9 |
Correct |
28 ms |
1708 KB |
Output is correct |
10 |
Correct |
24 ms |
1656 KB |
Output is correct |
11 |
Correct |
24 ms |
1668 KB |
Output is correct |
12 |
Correct |
23 ms |
1672 KB |
Output is correct |
13 |
Correct |
22 ms |
1636 KB |
Output is correct |
14 |
Correct |
21 ms |
1628 KB |
Output is correct |
15 |
Correct |
23 ms |
1660 KB |
Output is correct |
16 |
Correct |
27 ms |
1616 KB |
Output is correct |
17 |
Correct |
29 ms |
1620 KB |
Output is correct |
18 |
Correct |
26 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
724 KB |
Output is correct |
2 |
Correct |
14 ms |
852 KB |
Output is correct |
3 |
Correct |
27 ms |
1808 KB |
Output is correct |
4 |
Correct |
25 ms |
1756 KB |
Output is correct |
5 |
Correct |
31 ms |
1740 KB |
Output is correct |
6 |
Correct |
27 ms |
1724 KB |
Output is correct |
7 |
Correct |
27 ms |
1708 KB |
Output is correct |
8 |
Correct |
29 ms |
1740 KB |
Output is correct |
9 |
Correct |
28 ms |
1708 KB |
Output is correct |
10 |
Correct |
24 ms |
1656 KB |
Output is correct |
11 |
Correct |
24 ms |
1668 KB |
Output is correct |
12 |
Correct |
23 ms |
1672 KB |
Output is correct |
13 |
Correct |
22 ms |
1636 KB |
Output is correct |
14 |
Correct |
21 ms |
1628 KB |
Output is correct |
15 |
Correct |
23 ms |
1660 KB |
Output is correct |
16 |
Correct |
27 ms |
1616 KB |
Output is correct |
17 |
Correct |
29 ms |
1620 KB |
Output is correct |
18 |
Correct |
26 ms |
1624 KB |
Output is correct |
19 |
Correct |
92 ms |
5656 KB |
Output is correct |
20 |
Correct |
118 ms |
6352 KB |
Output is correct |
21 |
Correct |
118 ms |
6332 KB |
Output is correct |
22 |
Correct |
112 ms |
6316 KB |
Output is correct |
23 |
Correct |
93 ms |
6092 KB |
Output is correct |
24 |
Correct |
93 ms |
6076 KB |
Output is correct |
25 |
Correct |
97 ms |
6084 KB |
Output is correct |
26 |
Correct |
89 ms |
6028 KB |
Output is correct |
27 |
Correct |
82 ms |
5988 KB |
Output is correct |
28 |
Correct |
83 ms |
5984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
211 ms |
11576 KB |
Output is correct |
2 |
Correct |
481 ms |
24308 KB |
Output is correct |
3 |
Correct |
844 ms |
37176 KB |
Output is correct |
4 |
Correct |
851 ms |
37124 KB |
Output is correct |
5 |
Correct |
840 ms |
37124 KB |
Output is correct |
6 |
Correct |
908 ms |
36996 KB |
Output is correct |
7 |
Correct |
847 ms |
37048 KB |
Output is correct |
8 |
Correct |
879 ms |
37040 KB |
Output is correct |
9 |
Correct |
856 ms |
37000 KB |
Output is correct |
10 |
Correct |
500 ms |
33844 KB |
Output is correct |
11 |
Correct |
458 ms |
33868 KB |
Output is correct |
12 |
Correct |
459 ms |
33908 KB |
Output is correct |
13 |
Correct |
455 ms |
34036 KB |
Output is correct |
14 |
Correct |
466 ms |
33964 KB |
Output is correct |
15 |
Correct |
445 ms |
33844 KB |
Output is correct |
16 |
Correct |
433 ms |
34084 KB |
Output is correct |
17 |
Correct |
405 ms |
33948 KB |
Output is correct |
18 |
Correct |
426 ms |
33924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
724 KB |
Output is correct |
2 |
Correct |
14 ms |
852 KB |
Output is correct |
3 |
Correct |
27 ms |
1808 KB |
Output is correct |
4 |
Correct |
25 ms |
1756 KB |
Output is correct |
5 |
Correct |
31 ms |
1740 KB |
Output is correct |
6 |
Correct |
27 ms |
1724 KB |
Output is correct |
7 |
Correct |
27 ms |
1708 KB |
Output is correct |
8 |
Correct |
29 ms |
1740 KB |
Output is correct |
9 |
Correct |
28 ms |
1708 KB |
Output is correct |
10 |
Correct |
24 ms |
1656 KB |
Output is correct |
11 |
Correct |
24 ms |
1668 KB |
Output is correct |
12 |
Correct |
23 ms |
1672 KB |
Output is correct |
13 |
Correct |
22 ms |
1636 KB |
Output is correct |
14 |
Correct |
21 ms |
1628 KB |
Output is correct |
15 |
Correct |
23 ms |
1660 KB |
Output is correct |
16 |
Correct |
27 ms |
1616 KB |
Output is correct |
17 |
Correct |
29 ms |
1620 KB |
Output is correct |
18 |
Correct |
26 ms |
1624 KB |
Output is correct |
19 |
Correct |
92 ms |
5656 KB |
Output is correct |
20 |
Correct |
118 ms |
6352 KB |
Output is correct |
21 |
Correct |
118 ms |
6332 KB |
Output is correct |
22 |
Correct |
112 ms |
6316 KB |
Output is correct |
23 |
Correct |
93 ms |
6092 KB |
Output is correct |
24 |
Correct |
93 ms |
6076 KB |
Output is correct |
25 |
Correct |
97 ms |
6084 KB |
Output is correct |
26 |
Correct |
89 ms |
6028 KB |
Output is correct |
27 |
Correct |
82 ms |
5988 KB |
Output is correct |
28 |
Correct |
83 ms |
5984 KB |
Output is correct |
29 |
Correct |
211 ms |
11576 KB |
Output is correct |
30 |
Correct |
481 ms |
24308 KB |
Output is correct |
31 |
Correct |
844 ms |
37176 KB |
Output is correct |
32 |
Correct |
851 ms |
37124 KB |
Output is correct |
33 |
Correct |
840 ms |
37124 KB |
Output is correct |
34 |
Correct |
908 ms |
36996 KB |
Output is correct |
35 |
Correct |
847 ms |
37048 KB |
Output is correct |
36 |
Correct |
879 ms |
37040 KB |
Output is correct |
37 |
Correct |
856 ms |
37000 KB |
Output is correct |
38 |
Correct |
500 ms |
33844 KB |
Output is correct |
39 |
Correct |
458 ms |
33868 KB |
Output is correct |
40 |
Correct |
459 ms |
33908 KB |
Output is correct |
41 |
Correct |
455 ms |
34036 KB |
Output is correct |
42 |
Correct |
466 ms |
33964 KB |
Output is correct |
43 |
Correct |
445 ms |
33844 KB |
Output is correct |
44 |
Correct |
433 ms |
34084 KB |
Output is correct |
45 |
Correct |
405 ms |
33948 KB |
Output is correct |
46 |
Correct |
426 ms |
33924 KB |
Output is correct |
47 |
Correct |
3021 ms |
114644 KB |
Output is correct |
48 |
Execution timed out |
9106 ms |
347688 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |