Submission #625398

# Submission time Handle Problem Language Result Execution time Memory
625398 2022-08-10T10:54:18 Z MohamedFaresNebili Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3656 ms 144636 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
 
            using namespace std;
 
            using ll = long long;
            using ld = long double;
 
            #define ff first
            #define ss second
            #define pb push_back
            #define all(x) (x).begin(), (x).end()
            #define lb lower_bound
 
            const int MOD = 998244353;
            const int nx[4] = {-1, 0, 1, 0}, ny[4] = {0, 1, 0, -1};
            const int MX = 1000005;
 
            int ST[4000005], lazy[4000005], B[1000005];
            void prop(int v, int l, int r) {
                if(l == r || lazy[v] == 0)
                    return;
                lazy[v * 2] += lazy[v];
                lazy[v * 2 + 1] += lazy[v];
 
                ST[v * 2] += lazy[v];
                ST[v * 2 + 1] += lazy[v];
 
                lazy[v] = 0;
            }
            void update(int v, int l, int r, int lo, int hi, int val) {
                if(l > hi || r < lo) return;
                if(l >= lo && r <= hi) {
                    ST[v] += val; lazy[v] += val;
                    return;
                }
                prop(v, l, r);
                update(v * 2, l, (l + r) / 2, lo, hi, val);
                update(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi, val);
                ST[v] = max(ST[v * 2], ST[v * 2 + 1]);
            }
            void build(int v, int l, int r) {
                if(l == r) {
                    ST[v] = B[l];
                    return;
                }
                build(v * 2, l, (l + r) / 2);
                build(v * 2 + 1, (l + r) / 2 + 1, r);
                ST[v] = max(ST[v * 2], ST[v * 2 + 1]);
            }
 
            vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
                set<pair<int, int>> S; map<pair<int, int>, int> M;
                int N = A.size(), Q = X.size();
                for(int l = 0; l < N; l++) S.insert({A[l], l});
                for(int l = 0; l < Q; l++) S.insert({V[l], X[l]});
                int cur = 0;
                for(auto u : S) M[u] = cur++;
                for(int l = 0; l < N; l++) A[l] = M[{A[l], l}];
                for(int l = 0; l < N; l++) B[A[l]] = l;
                for(int l = 0; l < Q; l++) V[l] = M[{V[l], X[l]}];
                build(1, 0, MX - 1);
                for(int l = 0; l < N; l++)
                    update(1, 0, MX - 1, A[l] + 1, MX - 1, -1);
                vector<int> res(Q);
                for(int l = 0; l < Q; l++) {
                    int i = X[l];
                    int u = V[l], v = A[i];
                    update(1, 0, MX - 1, v + 1, MX - 1, 1);
                    update(1, 0, MX - 1, v, v, -i);
                    update(1, 0, MX - 1, u + 1, MX - 1, -1);
                    update(1, 0, MX - 1, u, u, i);
                    res[l] = ST[1];
                    A[i] = u;
                }
                return res;
            }
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8660 KB Output is correct
2 Correct 12 ms 8776 KB Output is correct
3 Correct 14 ms 9172 KB Output is correct
4 Correct 14 ms 9136 KB Output is correct
5 Correct 17 ms 9172 KB Output is correct
6 Correct 13 ms 9172 KB Output is correct
7 Correct 37 ms 9168 KB Output is correct
8 Correct 48 ms 9100 KB Output is correct
9 Correct 41 ms 9080 KB Output is correct
10 Correct 14 ms 9044 KB Output is correct
11 Correct 15 ms 9108 KB Output is correct
12 Correct 25 ms 9120 KB Output is correct
13 Correct 17 ms 9044 KB Output is correct
14 Correct 18 ms 8980 KB Output is correct
15 Correct 13 ms 9044 KB Output is correct
16 Correct 19 ms 9052 KB Output is correct
17 Correct 14 ms 9032 KB Output is correct
18 Correct 14 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8660 KB Output is correct
2 Correct 12 ms 8776 KB Output is correct
3 Correct 14 ms 9172 KB Output is correct
4 Correct 14 ms 9136 KB Output is correct
5 Correct 17 ms 9172 KB Output is correct
6 Correct 13 ms 9172 KB Output is correct
7 Correct 37 ms 9168 KB Output is correct
8 Correct 48 ms 9100 KB Output is correct
9 Correct 41 ms 9080 KB Output is correct
10 Correct 14 ms 9044 KB Output is correct
11 Correct 15 ms 9108 KB Output is correct
12 Correct 25 ms 9120 KB Output is correct
13 Correct 17 ms 9044 KB Output is correct
14 Correct 18 ms 8980 KB Output is correct
15 Correct 13 ms 9044 KB Output is correct
16 Correct 19 ms 9052 KB Output is correct
17 Correct 14 ms 9032 KB Output is correct
18 Correct 14 ms 9052 KB Output is correct
19 Correct 33 ms 10580 KB Output is correct
20 Correct 30 ms 10864 KB Output is correct
21 Correct 30 ms 10836 KB Output is correct
22 Correct 32 ms 10836 KB Output is correct
23 Correct 40 ms 10580 KB Output is correct
24 Correct 38 ms 10632 KB Output is correct
25 Correct 28 ms 10576 KB Output is correct
26 Correct 28 ms 10492 KB Output is correct
27 Correct 29 ms 10412 KB Output is correct
28 Correct 27 ms 10452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 12492 KB Output is correct
2 Correct 120 ms 17364 KB Output is correct
3 Correct 182 ms 22312 KB Output is correct
4 Correct 185 ms 22340 KB Output is correct
5 Correct 230 ms 22208 KB Output is correct
6 Correct 168 ms 21976 KB Output is correct
7 Correct 166 ms 22020 KB Output is correct
8 Correct 209 ms 22092 KB Output is correct
9 Correct 166 ms 22068 KB Output is correct
10 Correct 126 ms 16812 KB Output is correct
11 Correct 142 ms 16684 KB Output is correct
12 Correct 138 ms 16788 KB Output is correct
13 Correct 124 ms 16756 KB Output is correct
14 Correct 123 ms 16848 KB Output is correct
15 Correct 123 ms 16844 KB Output is correct
16 Correct 117 ms 16880 KB Output is correct
17 Correct 115 ms 16872 KB Output is correct
18 Correct 118 ms 16844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8660 KB Output is correct
2 Correct 12 ms 8776 KB Output is correct
3 Correct 14 ms 9172 KB Output is correct
4 Correct 14 ms 9136 KB Output is correct
5 Correct 17 ms 9172 KB Output is correct
6 Correct 13 ms 9172 KB Output is correct
7 Correct 37 ms 9168 KB Output is correct
8 Correct 48 ms 9100 KB Output is correct
9 Correct 41 ms 9080 KB Output is correct
10 Correct 14 ms 9044 KB Output is correct
11 Correct 15 ms 9108 KB Output is correct
12 Correct 25 ms 9120 KB Output is correct
13 Correct 17 ms 9044 KB Output is correct
14 Correct 18 ms 8980 KB Output is correct
15 Correct 13 ms 9044 KB Output is correct
16 Correct 19 ms 9052 KB Output is correct
17 Correct 14 ms 9032 KB Output is correct
18 Correct 14 ms 9052 KB Output is correct
19 Correct 33 ms 10580 KB Output is correct
20 Correct 30 ms 10864 KB Output is correct
21 Correct 30 ms 10836 KB Output is correct
22 Correct 32 ms 10836 KB Output is correct
23 Correct 40 ms 10580 KB Output is correct
24 Correct 38 ms 10632 KB Output is correct
25 Correct 28 ms 10576 KB Output is correct
26 Correct 28 ms 10492 KB Output is correct
27 Correct 29 ms 10412 KB Output is correct
28 Correct 27 ms 10452 KB Output is correct
29 Correct 48 ms 12492 KB Output is correct
30 Correct 120 ms 17364 KB Output is correct
31 Correct 182 ms 22312 KB Output is correct
32 Correct 185 ms 22340 KB Output is correct
33 Correct 230 ms 22208 KB Output is correct
34 Correct 168 ms 21976 KB Output is correct
35 Correct 166 ms 22020 KB Output is correct
36 Correct 209 ms 22092 KB Output is correct
37 Correct 166 ms 22068 KB Output is correct
38 Correct 126 ms 16812 KB Output is correct
39 Correct 142 ms 16684 KB Output is correct
40 Correct 138 ms 16788 KB Output is correct
41 Correct 124 ms 16756 KB Output is correct
42 Correct 123 ms 16848 KB Output is correct
43 Correct 123 ms 16844 KB Output is correct
44 Correct 117 ms 16880 KB Output is correct
45 Correct 115 ms 16872 KB Output is correct
46 Correct 118 ms 16844 KB Output is correct
47 Correct 772 ms 49256 KB Output is correct
48 Correct 3301 ms 132928 KB Output is correct
49 Correct 3599 ms 144460 KB Output is correct
50 Correct 3593 ms 144492 KB Output is correct
51 Correct 3656 ms 144408 KB Output is correct
52 Correct 3603 ms 144636 KB Output is correct
53 Correct 3623 ms 144544 KB Output is correct
54 Correct 3110 ms 144380 KB Output is correct
55 Correct 3470 ms 144540 KB Output is correct
56 Correct 3135 ms 144544 KB Output is correct
57 Correct 3376 ms 144552 KB Output is correct
58 Correct 3122 ms 144376 KB Output is correct
59 Correct 2892 ms 129344 KB Output is correct
60 Correct 2825 ms 129512 KB Output is correct
61 Correct 2790 ms 129352 KB Output is correct
62 Correct 2683 ms 121692 KB Output is correct
63 Correct 2690 ms 121688 KB Output is correct
64 Correct 2710 ms 121640 KB Output is correct
65 Correct 2571 ms 114148 KB Output is correct
66 Correct 2588 ms 113908 KB Output is correct
67 Correct 2542 ms 113552 KB Output is correct