답안 #625399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625399 2022-08-10T10:56:20 Z MohamedFaresNebili Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2623 ms 104872 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) {
                vector<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.push_back({A[l], l});
                for(int l = 0; l < Q; l++) S.push_back({V[l], X[l]});
                int cur = 0; sort(S.begin(), S.end());
                S.erase(unique(S.begin(), S.end()), S.end());
                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;
            }
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8660 KB Output is correct
2 Correct 14 ms 8660 KB Output is correct
3 Correct 13 ms 8916 KB Output is correct
4 Correct 14 ms 8916 KB Output is correct
5 Correct 12 ms 8928 KB Output is correct
6 Correct 12 ms 8868 KB Output is correct
7 Correct 12 ms 8972 KB Output is correct
8 Correct 13 ms 8912 KB Output is correct
9 Correct 13 ms 8968 KB Output is correct
10 Correct 12 ms 8880 KB Output is correct
11 Correct 17 ms 8928 KB Output is correct
12 Correct 15 ms 8916 KB Output is correct
13 Correct 15 ms 8856 KB Output is correct
14 Correct 12 ms 8916 KB Output is correct
15 Correct 12 ms 8916 KB Output is correct
16 Correct 11 ms 8916 KB Output is correct
17 Correct 12 ms 8788 KB Output is correct
18 Correct 11 ms 8860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8660 KB Output is correct
2 Correct 14 ms 8660 KB Output is correct
3 Correct 13 ms 8916 KB Output is correct
4 Correct 14 ms 8916 KB Output is correct
5 Correct 12 ms 8928 KB Output is correct
6 Correct 12 ms 8868 KB Output is correct
7 Correct 12 ms 8972 KB Output is correct
8 Correct 13 ms 8912 KB Output is correct
9 Correct 13 ms 8968 KB Output is correct
10 Correct 12 ms 8880 KB Output is correct
11 Correct 17 ms 8928 KB Output is correct
12 Correct 15 ms 8916 KB Output is correct
13 Correct 15 ms 8856 KB Output is correct
14 Correct 12 ms 8916 KB Output is correct
15 Correct 12 ms 8916 KB Output is correct
16 Correct 11 ms 8916 KB Output is correct
17 Correct 12 ms 8788 KB Output is correct
18 Correct 11 ms 8860 KB Output is correct
19 Correct 24 ms 9888 KB Output is correct
20 Correct 27 ms 10048 KB Output is correct
21 Correct 25 ms 10112 KB Output is correct
22 Correct 26 ms 10128 KB Output is correct
23 Correct 26 ms 9996 KB Output is correct
24 Correct 25 ms 9940 KB Output is correct
25 Correct 26 ms 9828 KB Output is correct
26 Correct 28 ms 9804 KB Output is correct
27 Correct 23 ms 9812 KB Output is correct
28 Correct 24 ms 9760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 11204 KB Output is correct
2 Correct 88 ms 14588 KB Output is correct
3 Correct 158 ms 18092 KB Output is correct
4 Correct 145 ms 18080 KB Output is correct
5 Correct 151 ms 18112 KB Output is correct
6 Correct 145 ms 18016 KB Output is correct
7 Correct 147 ms 17956 KB Output is correct
8 Correct 142 ms 17952 KB Output is correct
9 Correct 141 ms 18060 KB Output is correct
10 Correct 113 ms 14688 KB Output is correct
11 Correct 113 ms 14832 KB Output is correct
12 Correct 113 ms 14696 KB Output is correct
13 Correct 113 ms 14784 KB Output is correct
14 Correct 115 ms 14764 KB Output is correct
15 Correct 108 ms 14820 KB Output is correct
16 Correct 105 ms 14788 KB Output is correct
17 Correct 110 ms 14716 KB Output is correct
18 Correct 106 ms 14808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8660 KB Output is correct
2 Correct 14 ms 8660 KB Output is correct
3 Correct 13 ms 8916 KB Output is correct
4 Correct 14 ms 8916 KB Output is correct
5 Correct 12 ms 8928 KB Output is correct
6 Correct 12 ms 8868 KB Output is correct
7 Correct 12 ms 8972 KB Output is correct
8 Correct 13 ms 8912 KB Output is correct
9 Correct 13 ms 8968 KB Output is correct
10 Correct 12 ms 8880 KB Output is correct
11 Correct 17 ms 8928 KB Output is correct
12 Correct 15 ms 8916 KB Output is correct
13 Correct 15 ms 8856 KB Output is correct
14 Correct 12 ms 8916 KB Output is correct
15 Correct 12 ms 8916 KB Output is correct
16 Correct 11 ms 8916 KB Output is correct
17 Correct 12 ms 8788 KB Output is correct
18 Correct 11 ms 8860 KB Output is correct
19 Correct 24 ms 9888 KB Output is correct
20 Correct 27 ms 10048 KB Output is correct
21 Correct 25 ms 10112 KB Output is correct
22 Correct 26 ms 10128 KB Output is correct
23 Correct 26 ms 9996 KB Output is correct
24 Correct 25 ms 9940 KB Output is correct
25 Correct 26 ms 9828 KB Output is correct
26 Correct 28 ms 9804 KB Output is correct
27 Correct 23 ms 9812 KB Output is correct
28 Correct 24 ms 9760 KB Output is correct
29 Correct 34 ms 11204 KB Output is correct
30 Correct 88 ms 14588 KB Output is correct
31 Correct 158 ms 18092 KB Output is correct
32 Correct 145 ms 18080 KB Output is correct
33 Correct 151 ms 18112 KB Output is correct
34 Correct 145 ms 18016 KB Output is correct
35 Correct 147 ms 17956 KB Output is correct
36 Correct 142 ms 17952 KB Output is correct
37 Correct 141 ms 18060 KB Output is correct
38 Correct 113 ms 14688 KB Output is correct
39 Correct 113 ms 14832 KB Output is correct
40 Correct 113 ms 14696 KB Output is correct
41 Correct 113 ms 14784 KB Output is correct
42 Correct 115 ms 14764 KB Output is correct
43 Correct 108 ms 14820 KB Output is correct
44 Correct 105 ms 14788 KB Output is correct
45 Correct 110 ms 14716 KB Output is correct
46 Correct 106 ms 14808 KB Output is correct
47 Correct 609 ms 37212 KB Output is correct
48 Correct 2373 ms 96548 KB Output is correct
49 Correct 2591 ms 104800 KB Output is correct
50 Correct 2623 ms 104860 KB Output is correct
51 Correct 2558 ms 104872 KB Output is correct
52 Correct 2623 ms 104836 KB Output is correct
53 Correct 2583 ms 104728 KB Output is correct
54 Correct 2250 ms 104788 KB Output is correct
55 Correct 2562 ms 104788 KB Output is correct
56 Correct 2187 ms 104736 KB Output is correct
57 Correct 2359 ms 104756 KB Output is correct
58 Correct 2214 ms 104728 KB Output is correct
59 Correct 2123 ms 95480 KB Output is correct
60 Correct 2168 ms 95472 KB Output is correct
61 Correct 2111 ms 95416 KB Output is correct
62 Correct 2036 ms 90780 KB Output is correct
63 Correct 2033 ms 90796 KB Output is correct
64 Correct 2103 ms 90792 KB Output is correct
65 Correct 1907 ms 86132 KB Output is correct
66 Correct 1933 ms 86212 KB Output is correct
67 Correct 1934 ms 86144 KB Output is correct