답안 #747897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747897 2023-05-25T06:58:33 Z Sami_Massah Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
8702 ms 115224 KB
#include <bits/stdc++.h>
using namespace std;


const int maxn = 1e6 + 12, inf = 1e8;
int n, m, L[maxn * 4], R[maxn * 4], num[maxn * 4], mx[maxn * 4];
vector <int> ans;
vector <pair<int, int>> pos;

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);

        if (hash1 != hash2) {
            return hash1 ^ hash2;
        }

        // If hash1 == hash2, their XOR is zero.
          return hash1;
    }
};
unordered_map <pair<int, int>, int, hash_pair> cnv;
void make_tree(int l, int r, int ind){
    int mid = (l + r) / 2;
    L[ind] = l;
    R[ind] = r;
    if(l == r)
        return;
    make_tree(l, mid, ind * 2);
    make_tree(mid + 1, r, ind * 2 + 1);
}
void update_tree(int l, int r, int u, int k){
    if(r < L[u] || R[u] < l)
        return;
    if(l <= L[u] && R[u] <= r){
        num[u] += k;
        mx[u] += k;
        return;

    }
    update_tree(l, r, u * 2, k);
    update_tree(l, r, u * 2 + 1, k);
    mx[u] = max(mx[u * 2], mx[u * 2 + 1]) + num[u];
}
int get_max(int l, int r, int u){
    if(r < L[u] || R[u] < l)
        return 0;
    if(l <= L[u] && R[u] <= r)
        return mx[u];
    return max(get_max(l, r, u * 2), get_max(l, r, u * 2 + 1)) + num[u];
}
void set_tree(int l, int k){
    int x = get_max(l, l, 1);
    update_tree(l, l, 1, k - x);
}
vector <int> countScans(vector <int> a, vector <int> y, vector <int> x){
    n = a.size();
    m = x.size();
    for(int i = 0; i < m; i++)
        pos.push_back(make_pair(x[i], y[i]));
    for(int i = 0; i < n; i++)
        pos.push_back(make_pair(a[i], i));
    sort(pos.begin(), pos.end());
    int len = 1;
    for(auto i: pos)
        if(cnv[i] == 0){
            cnv[i] = len;
            len += 1;
        }
    make_tree(0, len, 1);

    for(int i = 0; i < n; i++){
        int now = cnv[make_pair(a[i], i)];
        update_tree(now + 1, len, 1, -1);
        update_tree(now, now, 1, i);
     //   cout << now + 1 << ' ' << len << endl;
 //       cout << now << endl << endl;
    }
   // cout << get_max(0, len, 1) << endl;
   // cout << endl;
    for(int i = 0; i < m; i++){
        int now = cnv[make_pair(a[y[i]], y[i])];
        update_tree(now + 1, len, 1, 1);
        update_tree(now, now, 1, -y[i]);

        now = cnv[make_pair(x[i], y[i])];
        update_tree(now + 1, len, 1, -1);
        update_tree(now, now, 1, y[i]);

        a[y[i]] = x[i];
        ans.push_back(get_max(0, len, 1));
    }
    return ans;


}
/*
int main(){
    vector <int> a, x, y;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        a.push_back(b);
    }
    for(int i = 0; i < m; i++){
        int b, c;
        cin >> b >> c;
        x.push_back(b);
        y.push_back(c);
    }
    countScans(a, x, y);
    for(int i: ans)
        cout << i << ' ';




}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 4 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 5 ms 724 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 6 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 6 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 4 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 5 ms 724 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 6 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 6 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 16 ms 1956 KB Output is correct
20 Correct 19 ms 2144 KB Output is correct
21 Correct 18 ms 2208 KB Output is correct
22 Correct 20 ms 2132 KB Output is correct
23 Correct 22 ms 2004 KB Output is correct
24 Correct 22 ms 2008 KB Output is correct
25 Correct 23 ms 1996 KB Output is correct
26 Correct 23 ms 2004 KB Output is correct
27 Correct 25 ms 1992 KB Output is correct
28 Correct 25 ms 1960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 3548 KB Output is correct
2 Correct 88 ms 7440 KB Output is correct
3 Correct 181 ms 12964 KB Output is correct
4 Correct 172 ms 12836 KB Output is correct
5 Correct 153 ms 12888 KB Output is correct
6 Correct 166 ms 12836 KB Output is correct
7 Correct 160 ms 12708 KB Output is correct
8 Correct 165 ms 12764 KB Output is correct
9 Correct 167 ms 12740 KB Output is correct
10 Correct 103 ms 7996 KB Output is correct
11 Correct 101 ms 7884 KB Output is correct
12 Correct 109 ms 7976 KB Output is correct
13 Correct 103 ms 7944 KB Output is correct
14 Correct 98 ms 8004 KB Output is correct
15 Correct 100 ms 7904 KB Output is correct
16 Correct 94 ms 7996 KB Output is correct
17 Correct 92 ms 8012 KB Output is correct
18 Correct 100 ms 8004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 4 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 5 ms 724 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 6 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 6 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 720 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 16 ms 1956 KB Output is correct
20 Correct 19 ms 2144 KB Output is correct
21 Correct 18 ms 2208 KB Output is correct
22 Correct 20 ms 2132 KB Output is correct
23 Correct 22 ms 2004 KB Output is correct
24 Correct 22 ms 2008 KB Output is correct
25 Correct 23 ms 1996 KB Output is correct
26 Correct 23 ms 2004 KB Output is correct
27 Correct 25 ms 1992 KB Output is correct
28 Correct 25 ms 1960 KB Output is correct
29 Correct 26 ms 3548 KB Output is correct
30 Correct 88 ms 7440 KB Output is correct
31 Correct 181 ms 12964 KB Output is correct
32 Correct 172 ms 12836 KB Output is correct
33 Correct 153 ms 12888 KB Output is correct
34 Correct 166 ms 12836 KB Output is correct
35 Correct 160 ms 12708 KB Output is correct
36 Correct 165 ms 12764 KB Output is correct
37 Correct 167 ms 12740 KB Output is correct
38 Correct 103 ms 7996 KB Output is correct
39 Correct 101 ms 7884 KB Output is correct
40 Correct 109 ms 7976 KB Output is correct
41 Correct 103 ms 7944 KB Output is correct
42 Correct 98 ms 8004 KB Output is correct
43 Correct 100 ms 7904 KB Output is correct
44 Correct 94 ms 7996 KB Output is correct
45 Correct 92 ms 8012 KB Output is correct
46 Correct 100 ms 8004 KB Output is correct
47 Correct 724 ms 40756 KB Output is correct
48 Correct 2689 ms 109236 KB Output is correct
49 Correct 2975 ms 114992 KB Output is correct
50 Correct 2797 ms 114992 KB Output is correct
51 Correct 2859 ms 115052 KB Output is correct
52 Correct 2799 ms 115132 KB Output is correct
53 Correct 2906 ms 115052 KB Output is correct
54 Correct 2732 ms 115176 KB Output is correct
55 Correct 2788 ms 115056 KB Output is correct
56 Correct 2670 ms 115104 KB Output is correct
57 Correct 2757 ms 115136 KB Output is correct
58 Correct 2676 ms 115224 KB Output is correct
59 Correct 7002 ms 109404 KB Output is correct
60 Correct 7066 ms 109280 KB Output is correct
61 Correct 7123 ms 109336 KB Output is correct
62 Correct 7631 ms 106360 KB Output is correct
63 Correct 7491 ms 106152 KB Output is correct
64 Correct 7459 ms 106316 KB Output is correct
65 Correct 8702 ms 103496 KB Output is correct
66 Correct 8632 ms 103548 KB Output is correct
67 Correct 8606 ms 103632 KB Output is correct