#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int inf = 1e9;
struct ST{
vector<int> a;
int n;
ST(int ns){
n = ns;
a.resize(n + 1);
}
void add(int l, int r, int x){
for (int i = l; i <= r; i++){
a[i] += x;
}
}
int get(){
int mx = 0;
for (int i = 1; i <= n; i++){
mx = max(mx, a[i]);
}
return mx;
}
};
vector<int> countScans(vector<int> a, vector<int> p, vector<int> x){
a.insert(a.begin(), 0);
p.insert(p.begin(), 0);
x.insert(x.begin(), 0);
int n = (int) a.size() - 1;
vector<int> all = {0};
for (int i = 1; i <= n; i++) all.pb(a[i]);
int q = (int) p.size() - 1;
for (int i = 1; i <= q; i++) p[i]++;
for (int i = 1; i <= q; i++) all.pb(x[i]);
sort(all.begin(), all.end());
vector<int> :: iterator it;
vector<int> y(n + 1);
map<int, int> mp;
for (int i = 1; i < all.size(); i++){
if (all[i] != all[i - 1]){
mp[all[i]] = i;
}
}
int m = (int) all.size() - 1;
ST T(m);
T.add(1, m, -inf);
auto rem = [&](int x){
it = lower_bound(all.begin(), all.end(), all[x]);
int j = (int) (it - all.begin());
T.add(1, j - 1, -1);
T.add(x, x, -inf);
};
auto add = [&](int x, int i){
it = lower_bound(all.begin(), all.end(), all[x]);
int j = (int) (it - all.begin());
T.add(1, j - 1, 1);
T.add(x, x, inf + i);
};
for (int i = 1; i <= n; i++){
y[i] = mp[a[i]]++;
add(y[i], i);
}
vector<int> out;
for (int i = 1; i <= q; i++){
rem(y[p[i]]);
y[p[i]] = mp[x[i]]++;
add(y[p[i]], p[i]);
out.pb(T.get() - n);
}
return out;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 1; i < all.size(); i++){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
4 ms |
592 KB |
Output is correct |
3 |
Correct |
12 ms |
760 KB |
Output is correct |
4 |
Correct |
12 ms |
592 KB |
Output is correct |
5 |
Correct |
13 ms |
592 KB |
Output is correct |
6 |
Correct |
13 ms |
780 KB |
Output is correct |
7 |
Correct |
13 ms |
780 KB |
Output is correct |
8 |
Correct |
12 ms |
592 KB |
Output is correct |
9 |
Correct |
12 ms |
792 KB |
Output is correct |
10 |
Correct |
15 ms |
592 KB |
Output is correct |
11 |
Correct |
14 ms |
592 KB |
Output is correct |
12 |
Correct |
12 ms |
764 KB |
Output is correct |
13 |
Correct |
13 ms |
760 KB |
Output is correct |
14 |
Correct |
13 ms |
592 KB |
Output is correct |
15 |
Correct |
16 ms |
592 KB |
Output is correct |
16 |
Correct |
13 ms |
592 KB |
Output is correct |
17 |
Correct |
13 ms |
592 KB |
Output is correct |
18 |
Correct |
12 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
4 ms |
592 KB |
Output is correct |
3 |
Correct |
12 ms |
760 KB |
Output is correct |
4 |
Correct |
12 ms |
592 KB |
Output is correct |
5 |
Correct |
13 ms |
592 KB |
Output is correct |
6 |
Correct |
13 ms |
780 KB |
Output is correct |
7 |
Correct |
13 ms |
780 KB |
Output is correct |
8 |
Correct |
12 ms |
592 KB |
Output is correct |
9 |
Correct |
12 ms |
792 KB |
Output is correct |
10 |
Correct |
15 ms |
592 KB |
Output is correct |
11 |
Correct |
14 ms |
592 KB |
Output is correct |
12 |
Correct |
12 ms |
764 KB |
Output is correct |
13 |
Correct |
13 ms |
760 KB |
Output is correct |
14 |
Correct |
13 ms |
592 KB |
Output is correct |
15 |
Correct |
16 ms |
592 KB |
Output is correct |
16 |
Correct |
13 ms |
592 KB |
Output is correct |
17 |
Correct |
13 ms |
592 KB |
Output is correct |
18 |
Correct |
12 ms |
592 KB |
Output is correct |
19 |
Correct |
133 ms |
1604 KB |
Output is correct |
20 |
Correct |
193 ms |
1616 KB |
Output is correct |
21 |
Correct |
182 ms |
1764 KB |
Output is correct |
22 |
Correct |
175 ms |
1872 KB |
Output is correct |
23 |
Correct |
166 ms |
1632 KB |
Output is correct |
24 |
Correct |
192 ms |
1632 KB |
Output is correct |
25 |
Correct |
178 ms |
1608 KB |
Output is correct |
26 |
Correct |
178 ms |
1584 KB |
Output is correct |
27 |
Correct |
180 ms |
1608 KB |
Output is correct |
28 |
Correct |
185 ms |
1608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
848 KB |
Output is correct |
2 |
Correct |
2328 ms |
2416 KB |
Output is correct |
3 |
Correct |
6344 ms |
3416 KB |
Output is correct |
4 |
Correct |
6343 ms |
3564 KB |
Output is correct |
5 |
Correct |
6743 ms |
3600 KB |
Output is correct |
6 |
Correct |
6421 ms |
3584 KB |
Output is correct |
7 |
Correct |
6461 ms |
3396 KB |
Output is correct |
8 |
Correct |
6681 ms |
3572 KB |
Output is correct |
9 |
Correct |
6552 ms |
3572 KB |
Output is correct |
10 |
Correct |
4674 ms |
3676 KB |
Output is correct |
11 |
Correct |
4990 ms |
3688 KB |
Output is correct |
12 |
Correct |
4670 ms |
3504 KB |
Output is correct |
13 |
Correct |
5252 ms |
3548 KB |
Output is correct |
14 |
Correct |
4991 ms |
3672 KB |
Output is correct |
15 |
Correct |
5246 ms |
3684 KB |
Output is correct |
16 |
Correct |
5383 ms |
3604 KB |
Output is correct |
17 |
Correct |
5396 ms |
3600 KB |
Output is correct |
18 |
Correct |
5246 ms |
3464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
4 ms |
592 KB |
Output is correct |
3 |
Correct |
12 ms |
760 KB |
Output is correct |
4 |
Correct |
12 ms |
592 KB |
Output is correct |
5 |
Correct |
13 ms |
592 KB |
Output is correct |
6 |
Correct |
13 ms |
780 KB |
Output is correct |
7 |
Correct |
13 ms |
780 KB |
Output is correct |
8 |
Correct |
12 ms |
592 KB |
Output is correct |
9 |
Correct |
12 ms |
792 KB |
Output is correct |
10 |
Correct |
15 ms |
592 KB |
Output is correct |
11 |
Correct |
14 ms |
592 KB |
Output is correct |
12 |
Correct |
12 ms |
764 KB |
Output is correct |
13 |
Correct |
13 ms |
760 KB |
Output is correct |
14 |
Correct |
13 ms |
592 KB |
Output is correct |
15 |
Correct |
16 ms |
592 KB |
Output is correct |
16 |
Correct |
13 ms |
592 KB |
Output is correct |
17 |
Correct |
13 ms |
592 KB |
Output is correct |
18 |
Correct |
12 ms |
592 KB |
Output is correct |
19 |
Correct |
133 ms |
1604 KB |
Output is correct |
20 |
Correct |
193 ms |
1616 KB |
Output is correct |
21 |
Correct |
182 ms |
1764 KB |
Output is correct |
22 |
Correct |
175 ms |
1872 KB |
Output is correct |
23 |
Correct |
166 ms |
1632 KB |
Output is correct |
24 |
Correct |
192 ms |
1632 KB |
Output is correct |
25 |
Correct |
178 ms |
1608 KB |
Output is correct |
26 |
Correct |
178 ms |
1584 KB |
Output is correct |
27 |
Correct |
180 ms |
1608 KB |
Output is correct |
28 |
Correct |
185 ms |
1608 KB |
Output is correct |
29 |
Correct |
223 ms |
848 KB |
Output is correct |
30 |
Correct |
2328 ms |
2416 KB |
Output is correct |
31 |
Correct |
6344 ms |
3416 KB |
Output is correct |
32 |
Correct |
6343 ms |
3564 KB |
Output is correct |
33 |
Correct |
6743 ms |
3600 KB |
Output is correct |
34 |
Correct |
6421 ms |
3584 KB |
Output is correct |
35 |
Correct |
6461 ms |
3396 KB |
Output is correct |
36 |
Correct |
6681 ms |
3572 KB |
Output is correct |
37 |
Correct |
6552 ms |
3572 KB |
Output is correct |
38 |
Correct |
4674 ms |
3676 KB |
Output is correct |
39 |
Correct |
4990 ms |
3688 KB |
Output is correct |
40 |
Correct |
4670 ms |
3504 KB |
Output is correct |
41 |
Correct |
5252 ms |
3548 KB |
Output is correct |
42 |
Correct |
4991 ms |
3672 KB |
Output is correct |
43 |
Correct |
5246 ms |
3684 KB |
Output is correct |
44 |
Correct |
5383 ms |
3604 KB |
Output is correct |
45 |
Correct |
5396 ms |
3600 KB |
Output is correct |
46 |
Correct |
5246 ms |
3464 KB |
Output is correct |
47 |
Execution timed out |
9058 ms |
25240 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |