Submission #625395

# Submission time Handle Problem Language Result Execution time Memory
625395 2022-08-10T10:51:23 Z MohamedFaresNebili Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3964 ms 153052 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 = 2000005;

            int ST[8000005], lazy[8000005], B[8000005];
            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 21 ms 16932 KB Output is correct
2 Correct 26 ms 17032 KB Output is correct
3 Correct 24 ms 17280 KB Output is correct
4 Correct 23 ms 17388 KB Output is correct
5 Correct 30 ms 17384 KB Output is correct
6 Correct 23 ms 17392 KB Output is correct
7 Correct 28 ms 17328 KB Output is correct
8 Correct 24 ms 17316 KB Output is correct
9 Correct 26 ms 17332 KB Output is correct
10 Correct 22 ms 17236 KB Output is correct
11 Correct 23 ms 17272 KB Output is correct
12 Correct 23 ms 17260 KB Output is correct
13 Correct 23 ms 17308 KB Output is correct
14 Correct 23 ms 17228 KB Output is correct
15 Correct 22 ms 17260 KB Output is correct
16 Correct 23 ms 17220 KB Output is correct
17 Correct 28 ms 17172 KB Output is correct
18 Correct 23 ms 17208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 16932 KB Output is correct
2 Correct 26 ms 17032 KB Output is correct
3 Correct 24 ms 17280 KB Output is correct
4 Correct 23 ms 17388 KB Output is correct
5 Correct 30 ms 17384 KB Output is correct
6 Correct 23 ms 17392 KB Output is correct
7 Correct 28 ms 17328 KB Output is correct
8 Correct 24 ms 17316 KB Output is correct
9 Correct 26 ms 17332 KB Output is correct
10 Correct 22 ms 17236 KB Output is correct
11 Correct 23 ms 17272 KB Output is correct
12 Correct 23 ms 17260 KB Output is correct
13 Correct 23 ms 17308 KB Output is correct
14 Correct 23 ms 17228 KB Output is correct
15 Correct 22 ms 17260 KB Output is correct
16 Correct 23 ms 17220 KB Output is correct
17 Correct 28 ms 17172 KB Output is correct
18 Correct 23 ms 17208 KB Output is correct
19 Correct 37 ms 18880 KB Output is correct
20 Correct 49 ms 19192 KB Output is correct
21 Correct 42 ms 19132 KB Output is correct
22 Correct 41 ms 19132 KB Output is correct
23 Correct 39 ms 18856 KB Output is correct
24 Correct 39 ms 18892 KB Output is correct
25 Correct 41 ms 18772 KB Output is correct
26 Correct 40 ms 18748 KB Output is correct
27 Correct 38 ms 18604 KB Output is correct
28 Correct 40 ms 18576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 20812 KB Output is correct
2 Correct 118 ms 25684 KB Output is correct
3 Correct 196 ms 30748 KB Output is correct
4 Correct 188 ms 30672 KB Output is correct
5 Correct 195 ms 30688 KB Output is correct
6 Correct 192 ms 30412 KB Output is correct
7 Correct 183 ms 30684 KB Output is correct
8 Correct 237 ms 30548 KB Output is correct
9 Correct 177 ms 30440 KB Output is correct
10 Correct 148 ms 25292 KB Output is correct
11 Correct 145 ms 25268 KB Output is correct
12 Correct 176 ms 25296 KB Output is correct
13 Correct 137 ms 25220 KB Output is correct
14 Correct 177 ms 25332 KB Output is correct
15 Correct 139 ms 25332 KB Output is correct
16 Correct 129 ms 25288 KB Output is correct
17 Correct 152 ms 25264 KB Output is correct
18 Correct 129 ms 25248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 16932 KB Output is correct
2 Correct 26 ms 17032 KB Output is correct
3 Correct 24 ms 17280 KB Output is correct
4 Correct 23 ms 17388 KB Output is correct
5 Correct 30 ms 17384 KB Output is correct
6 Correct 23 ms 17392 KB Output is correct
7 Correct 28 ms 17328 KB Output is correct
8 Correct 24 ms 17316 KB Output is correct
9 Correct 26 ms 17332 KB Output is correct
10 Correct 22 ms 17236 KB Output is correct
11 Correct 23 ms 17272 KB Output is correct
12 Correct 23 ms 17260 KB Output is correct
13 Correct 23 ms 17308 KB Output is correct
14 Correct 23 ms 17228 KB Output is correct
15 Correct 22 ms 17260 KB Output is correct
16 Correct 23 ms 17220 KB Output is correct
17 Correct 28 ms 17172 KB Output is correct
18 Correct 23 ms 17208 KB Output is correct
19 Correct 37 ms 18880 KB Output is correct
20 Correct 49 ms 19192 KB Output is correct
21 Correct 42 ms 19132 KB Output is correct
22 Correct 41 ms 19132 KB Output is correct
23 Correct 39 ms 18856 KB Output is correct
24 Correct 39 ms 18892 KB Output is correct
25 Correct 41 ms 18772 KB Output is correct
26 Correct 40 ms 18748 KB Output is correct
27 Correct 38 ms 18604 KB Output is correct
28 Correct 40 ms 18576 KB Output is correct
29 Correct 51 ms 20812 KB Output is correct
30 Correct 118 ms 25684 KB Output is correct
31 Correct 196 ms 30748 KB Output is correct
32 Correct 188 ms 30672 KB Output is correct
33 Correct 195 ms 30688 KB Output is correct
34 Correct 192 ms 30412 KB Output is correct
35 Correct 183 ms 30684 KB Output is correct
36 Correct 237 ms 30548 KB Output is correct
37 Correct 177 ms 30440 KB Output is correct
38 Correct 148 ms 25292 KB Output is correct
39 Correct 145 ms 25268 KB Output is correct
40 Correct 176 ms 25296 KB Output is correct
41 Correct 137 ms 25220 KB Output is correct
42 Correct 177 ms 25332 KB Output is correct
43 Correct 139 ms 25332 KB Output is correct
44 Correct 129 ms 25288 KB Output is correct
45 Correct 152 ms 25264 KB Output is correct
46 Correct 129 ms 25248 KB Output is correct
47 Correct 819 ms 57456 KB Output is correct
48 Correct 3628 ms 141096 KB Output is correct
49 Correct 3841 ms 152784 KB Output is correct
50 Correct 3848 ms 152884 KB Output is correct
51 Correct 3779 ms 153028 KB Output is correct
52 Correct 3845 ms 152876 KB Output is correct
53 Correct 3964 ms 152884 KB Output is correct
54 Correct 3444 ms 152932 KB Output is correct
55 Correct 3822 ms 153052 KB Output is correct
56 Correct 3349 ms 152836 KB Output is correct
57 Correct 3681 ms 152732 KB Output is correct
58 Correct 3378 ms 152728 KB Output is correct
59 Correct 3113 ms 137556 KB Output is correct
60 Correct 3018 ms 137436 KB Output is correct
61 Correct 2974 ms 137476 KB Output is correct
62 Correct 2872 ms 130020 KB Output is correct
63 Correct 2936 ms 129708 KB Output is correct
64 Correct 2964 ms 129872 KB Output is correct
65 Correct 2803 ms 122180 KB Output is correct
66 Correct 2805 ms 122280 KB Output is correct
67 Correct 2748 ms 122020 KB Output is correct