Submission #444009

# Submission time Handle Problem Language Result Execution time Memory
444009 2021-07-13T00:14:50 Z SirCovidThe19th Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2735 ms 53372 KB
#include <bits/stdc++.h>
using namespace std; 

#define vi vector<int>
#define all(x) x.begin(), x.end()

const int mx = (1<<20); int seg[mx*2], lz[mx*2]; vector<pair<int, int>> mp; vi ans;

void upd(int x, int y, int v, int l = 0, int r = mp.size()-1, int i = 1){
    if (l > y or r < x) return;
    if (l >= x and r <= y){ seg[i] += v, lz[i] += v; return; }
    int m = (l+r)/2; upd(x, y, v, l, m, i*2); upd(x, y, v, m+1, r, i*2+1);
    seg[i] = max(seg[i*2], seg[i*2+1])+lz[i];
}
vi countScans(vi A, vi X, vi V){
    for (int i = 0; i < A.size(); i++) mp.push_back({A[i], i});
    for (int i = 0; i < X.size(); i++) mp.push_back({V[i], X[i]});
    sort(all(mp)); mp.erase(unique(all(mp)), mp.end());
    auto lb = [&](pair<int, int> x){ return lower_bound(all(mp), x)-mp.begin(); };    
    auto app = [&](int i, int sgn){// i - elems less/eq
        int p = lb({A[i], i}); upd(p, p, (i+1)*sgn);
        p = lb({A[i], -1}); upd(p, mp.size()-1, -sgn);
    };for (int i = 0; i < A.size(); i++) app(i, 1);
    for (int i = 0; i < X.size(); i++){
        app(X[i], -1); A[X[i]] = V[i]; app(X[i], 1);
        ans.push_back(seg[1]);
    }return ans;
}


Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < A.size(); i++) mp.push_back({A[i], i});
      |                     ~~^~~~~~~~~~
bubblesort2.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < X.size(); i++) mp.push_back({V[i], X[i]});
      |                     ~~^~~~~~~~~~
bubblesort2.cpp:23:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     };for (int i = 0; i < A.size(); i++) app(i, 1);
      |                       ~~^~~~~~~~~~
bubblesort2.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < X.size(); i++){
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 6 ms 532 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
5 Correct 5 ms 460 KB Output is correct
6 Correct 5 ms 440 KB Output is correct
7 Correct 5 ms 460 KB Output is correct
8 Correct 5 ms 440 KB Output is correct
9 Correct 5 ms 460 KB Output is correct
10 Correct 5 ms 460 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 5 ms 460 KB Output is correct
14 Correct 5 ms 520 KB Output is correct
15 Correct 5 ms 436 KB Output is correct
16 Correct 5 ms 532 KB Output is correct
17 Correct 5 ms 520 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 6 ms 532 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
5 Correct 5 ms 460 KB Output is correct
6 Correct 5 ms 440 KB Output is correct
7 Correct 5 ms 460 KB Output is correct
8 Correct 5 ms 440 KB Output is correct
9 Correct 5 ms 460 KB Output is correct
10 Correct 5 ms 460 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 5 ms 460 KB Output is correct
14 Correct 5 ms 520 KB Output is correct
15 Correct 5 ms 436 KB Output is correct
16 Correct 5 ms 532 KB Output is correct
17 Correct 5 ms 520 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
19 Correct 19 ms 1144 KB Output is correct
20 Correct 22 ms 1228 KB Output is correct
21 Correct 21 ms 1216 KB Output is correct
22 Correct 24 ms 1212 KB Output is correct
23 Correct 21 ms 1176 KB Output is correct
24 Correct 21 ms 1180 KB Output is correct
25 Correct 21 ms 1100 KB Output is correct
26 Correct 21 ms 1180 KB Output is correct
27 Correct 20 ms 1100 KB Output is correct
28 Correct 23 ms 1180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1480 KB Output is correct
2 Correct 87 ms 3008 KB Output is correct
3 Correct 163 ms 5256 KB Output is correct
4 Correct 158 ms 5200 KB Output is correct
5 Correct 158 ms 5284 KB Output is correct
6 Correct 158 ms 5284 KB Output is correct
7 Correct 152 ms 5220 KB Output is correct
8 Correct 155 ms 5244 KB Output is correct
9 Correct 152 ms 5304 KB Output is correct
10 Correct 127 ms 4292 KB Output is correct
11 Correct 127 ms 4240 KB Output is correct
12 Correct 129 ms 4324 KB Output is correct
13 Correct 125 ms 4208 KB Output is correct
14 Correct 132 ms 4288 KB Output is correct
15 Correct 121 ms 4280 KB Output is correct
16 Correct 120 ms 4216 KB Output is correct
17 Correct 122 ms 4220 KB Output is correct
18 Correct 123 ms 4280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 6 ms 532 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
5 Correct 5 ms 460 KB Output is correct
6 Correct 5 ms 440 KB Output is correct
7 Correct 5 ms 460 KB Output is correct
8 Correct 5 ms 440 KB Output is correct
9 Correct 5 ms 460 KB Output is correct
10 Correct 5 ms 460 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 5 ms 460 KB Output is correct
14 Correct 5 ms 520 KB Output is correct
15 Correct 5 ms 436 KB Output is correct
16 Correct 5 ms 532 KB Output is correct
17 Correct 5 ms 520 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
19 Correct 19 ms 1144 KB Output is correct
20 Correct 22 ms 1228 KB Output is correct
21 Correct 21 ms 1216 KB Output is correct
22 Correct 24 ms 1212 KB Output is correct
23 Correct 21 ms 1176 KB Output is correct
24 Correct 21 ms 1180 KB Output is correct
25 Correct 21 ms 1100 KB Output is correct
26 Correct 21 ms 1180 KB Output is correct
27 Correct 20 ms 1100 KB Output is correct
28 Correct 23 ms 1180 KB Output is correct
29 Correct 30 ms 1480 KB Output is correct
30 Correct 87 ms 3008 KB Output is correct
31 Correct 163 ms 5256 KB Output is correct
32 Correct 158 ms 5200 KB Output is correct
33 Correct 158 ms 5284 KB Output is correct
34 Correct 158 ms 5284 KB Output is correct
35 Correct 152 ms 5220 KB Output is correct
36 Correct 155 ms 5244 KB Output is correct
37 Correct 152 ms 5304 KB Output is correct
38 Correct 127 ms 4292 KB Output is correct
39 Correct 127 ms 4240 KB Output is correct
40 Correct 129 ms 4324 KB Output is correct
41 Correct 125 ms 4208 KB Output is correct
42 Correct 132 ms 4288 KB Output is correct
43 Correct 121 ms 4280 KB Output is correct
44 Correct 120 ms 4216 KB Output is correct
45 Correct 122 ms 4220 KB Output is correct
46 Correct 123 ms 4280 KB Output is correct
47 Correct 601 ms 19500 KB Output is correct
48 Correct 2366 ms 50688 KB Output is correct
49 Correct 2569 ms 53284 KB Output is correct
50 Correct 2571 ms 53148 KB Output is correct
51 Correct 2512 ms 53116 KB Output is correct
52 Correct 2575 ms 53176 KB Output is correct
53 Correct 2595 ms 53132 KB Output is correct
54 Correct 2464 ms 53344 KB Output is correct
55 Correct 2735 ms 53372 KB Output is correct
56 Correct 2417 ms 53260 KB Output is correct
57 Correct 2499 ms 53276 KB Output is correct
58 Correct 2350 ms 53336 KB Output is correct
59 Correct 2156 ms 52128 KB Output is correct
60 Correct 2179 ms 52068 KB Output is correct
61 Correct 2188 ms 52096 KB Output is correct
62 Correct 2055 ms 51868 KB Output is correct
63 Correct 2052 ms 51876 KB Output is correct
64 Correct 2055 ms 51864 KB Output is correct
65 Correct 1967 ms 51812 KB Output is correct
66 Correct 1944 ms 51748 KB Output is correct
67 Correct 1940 ms 51680 KB Output is correct