답안 #249130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249130 2020-07-14T12:02:55 Z egekabas Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3626 ms 217824 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int seg[8000009];
int lazy[8000009];
void push(int v){
    lazy[2*v] += lazy[v];
    lazy[2*v+1] += lazy[v];
    seg[2*v] += lazy[v];
    seg[2*v+1] += lazy[v];
    lazy[v] = 0;
}
void upd(int v, int tl, int tr, int l, int r, int val){
    if(r < tl || tr < l) return;
    if(l <= tl && tr <= r){
        seg[v] += val;
        lazy[v] += val;
    }
    else{
        push(v);
        upd(2*v, tl, (tl+tr)/2, l, r, val);
        upd(2*v+1, (tl+tr)/2+1, tr, l, r, val);
        seg[v] = max(seg[2*v], seg[2*v+1]);
    }
}
map<int, int> mpp;

set<int, greater<int>> s[2000009];
int n, N;
int q;
vector<int> a, x, v;

void erase(int idx){
    if(*s[a[idx]].begin() == idx+1){
        upd(1, 0, N, a[idx], a[idx], -(idx+1));
        s[a[idx]].erase(idx+1);
        if(s[a[idx]].size())
            upd(1, 0, N, a[idx], a[idx], *s[a[idx]].begin());
    }
    else
        s[a[idx]].erase(idx+1);
    upd(1, 0, N, a[idx], N, 1);
}
void add(int idx){
    if(s[a[idx]].empty()){
        upd(1, 0, N, a[idx], a[idx], (idx+1));        
    }
    else if(idx+1 > *s[a[idx]].begin()){
        upd(1, 0, N, a[idx], a[idx], -*s[a[idx]].begin());
        upd(1, 0, N, a[idx], a[idx], (idx+1));    
    }
    s[a[idx]].insert(idx+1);
    upd(1, 0, N, a[idx], N, -1);
}
vector<int> countScans(vector<int> a1, vector<int> a2, vector<int> a3){
    a = a1;
    x = a2;
    v = a3;
    n = a.size();
    q = v.size();
    vector<int> tmp;
    for(auto u : a)
        tmp.pb(u);
    for(auto u : v)
        tmp.pb(u);
    sort(tmp.begin(), tmp.end());
    tmp.resize(unique(tmp.begin(), tmp.end())-tmp.begin());
    N = tmp.size();
    for(int i = 0; i < tmp.size(); ++i)
        mpp[tmp[i]] = i;
    for(int i = 0; i < n; ++i)
        a[i] = mpp[a[i]];
    for(int i = 0; i < q; ++i)
        v[i] = mpp[v[i]];
    
    for(int i = 0; i < n; ++i)
        add(i);
    vector<int> ans(q);
    for(int i = 0; i < q; ++i){
        erase(x[i]);
        a[x[i]] = v[i];
        add(x[i]);
        ans[i] = max(seg[1], 0);
    }
    return ans;
}
/*int main(){

    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int n, q;
    cin >> n >> q;
    vector<int> a(n), x(q), v(q);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    for(int i = 0; i < q; ++i)
        cin >> x[i] >> v[i];
    vector<int> ans = countScans(a, x, v);
    for(auto u : ans)
        cout << u << '\n';
}*/

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:79:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < tmp.size(); ++i)
                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 94456 KB Output is correct
2 Correct 54 ms 94456 KB Output is correct
3 Correct 60 ms 94712 KB Output is correct
4 Correct 57 ms 94712 KB Output is correct
5 Correct 57 ms 94712 KB Output is correct
6 Correct 58 ms 94712 KB Output is correct
7 Correct 56 ms 94712 KB Output is correct
8 Correct 58 ms 94800 KB Output is correct
9 Correct 62 ms 94712 KB Output is correct
10 Correct 56 ms 94712 KB Output is correct
11 Correct 57 ms 94712 KB Output is correct
12 Correct 59 ms 94712 KB Output is correct
13 Correct 57 ms 94712 KB Output is correct
14 Correct 56 ms 94712 KB Output is correct
15 Correct 56 ms 94712 KB Output is correct
16 Correct 56 ms 94716 KB Output is correct
17 Correct 55 ms 94712 KB Output is correct
18 Correct 55 ms 94712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 94456 KB Output is correct
2 Correct 54 ms 94456 KB Output is correct
3 Correct 60 ms 94712 KB Output is correct
4 Correct 57 ms 94712 KB Output is correct
5 Correct 57 ms 94712 KB Output is correct
6 Correct 58 ms 94712 KB Output is correct
7 Correct 56 ms 94712 KB Output is correct
8 Correct 58 ms 94800 KB Output is correct
9 Correct 62 ms 94712 KB Output is correct
10 Correct 56 ms 94712 KB Output is correct
11 Correct 57 ms 94712 KB Output is correct
12 Correct 59 ms 94712 KB Output is correct
13 Correct 57 ms 94712 KB Output is correct
14 Correct 56 ms 94712 KB Output is correct
15 Correct 56 ms 94712 KB Output is correct
16 Correct 56 ms 94716 KB Output is correct
17 Correct 55 ms 94712 KB Output is correct
18 Correct 55 ms 94712 KB Output is correct
19 Correct 72 ms 95992 KB Output is correct
20 Correct 75 ms 96248 KB Output is correct
21 Correct 76 ms 96248 KB Output is correct
22 Correct 76 ms 96248 KB Output is correct
23 Correct 73 ms 96120 KB Output is correct
24 Correct 76 ms 96120 KB Output is correct
25 Correct 72 ms 96120 KB Output is correct
26 Correct 74 ms 96120 KB Output is correct
27 Correct 72 ms 95992 KB Output is correct
28 Correct 71 ms 95992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 96132 KB Output is correct
2 Correct 107 ms 97908 KB Output is correct
3 Correct 153 ms 99568 KB Output is correct
4 Correct 157 ms 99568 KB Output is correct
5 Correct 153 ms 99568 KB Output is correct
6 Correct 152 ms 99556 KB Output is correct
7 Correct 146 ms 99568 KB Output is correct
8 Correct 147 ms 99572 KB Output is correct
9 Correct 145 ms 99568 KB Output is correct
10 Correct 130 ms 99568 KB Output is correct
11 Correct 133 ms 99568 KB Output is correct
12 Correct 132 ms 99568 KB Output is correct
13 Correct 129 ms 99572 KB Output is correct
14 Correct 142 ms 99568 KB Output is correct
15 Correct 125 ms 99568 KB Output is correct
16 Correct 123 ms 99568 KB Output is correct
17 Correct 123 ms 99568 KB Output is correct
18 Correct 124 ms 99568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 94456 KB Output is correct
2 Correct 54 ms 94456 KB Output is correct
3 Correct 60 ms 94712 KB Output is correct
4 Correct 57 ms 94712 KB Output is correct
5 Correct 57 ms 94712 KB Output is correct
6 Correct 58 ms 94712 KB Output is correct
7 Correct 56 ms 94712 KB Output is correct
8 Correct 58 ms 94800 KB Output is correct
9 Correct 62 ms 94712 KB Output is correct
10 Correct 56 ms 94712 KB Output is correct
11 Correct 57 ms 94712 KB Output is correct
12 Correct 59 ms 94712 KB Output is correct
13 Correct 57 ms 94712 KB Output is correct
14 Correct 56 ms 94712 KB Output is correct
15 Correct 56 ms 94712 KB Output is correct
16 Correct 56 ms 94716 KB Output is correct
17 Correct 55 ms 94712 KB Output is correct
18 Correct 55 ms 94712 KB Output is correct
19 Correct 72 ms 95992 KB Output is correct
20 Correct 75 ms 96248 KB Output is correct
21 Correct 76 ms 96248 KB Output is correct
22 Correct 76 ms 96248 KB Output is correct
23 Correct 73 ms 96120 KB Output is correct
24 Correct 76 ms 96120 KB Output is correct
25 Correct 72 ms 96120 KB Output is correct
26 Correct 74 ms 96120 KB Output is correct
27 Correct 72 ms 95992 KB Output is correct
28 Correct 71 ms 95992 KB Output is correct
29 Correct 73 ms 96132 KB Output is correct
30 Correct 107 ms 97908 KB Output is correct
31 Correct 153 ms 99568 KB Output is correct
32 Correct 157 ms 99568 KB Output is correct
33 Correct 153 ms 99568 KB Output is correct
34 Correct 152 ms 99556 KB Output is correct
35 Correct 146 ms 99568 KB Output is correct
36 Correct 147 ms 99572 KB Output is correct
37 Correct 145 ms 99568 KB Output is correct
38 Correct 130 ms 99568 KB Output is correct
39 Correct 133 ms 99568 KB Output is correct
40 Correct 132 ms 99568 KB Output is correct
41 Correct 129 ms 99572 KB Output is correct
42 Correct 142 ms 99568 KB Output is correct
43 Correct 125 ms 99568 KB Output is correct
44 Correct 123 ms 99568 KB Output is correct
45 Correct 123 ms 99568 KB Output is correct
46 Correct 124 ms 99568 KB Output is correct
47 Correct 828 ms 134376 KB Output is correct
48 Correct 3169 ms 207556 KB Output is correct
49 Correct 3626 ms 217452 KB Output is correct
50 Correct 3580 ms 217464 KB Output is correct
51 Correct 3602 ms 217588 KB Output is correct
52 Correct 3376 ms 217544 KB Output is correct
53 Correct 3489 ms 217568 KB Output is correct
54 Correct 3042 ms 217712 KB Output is correct
55 Correct 3197 ms 217824 KB Output is correct
56 Correct 3109 ms 217636 KB Output is correct
57 Correct 3234 ms 217704 KB Output is correct
58 Correct 3160 ms 217608 KB Output is correct
59 Correct 3016 ms 210552 KB Output is correct
60 Correct 2787 ms 210528 KB Output is correct
61 Correct 2882 ms 210656 KB Output is correct
62 Correct 2633 ms 207504 KB Output is correct
63 Correct 2811 ms 207528 KB Output is correct
64 Correct 2687 ms 207524 KB Output is correct
65 Correct 2558 ms 204456 KB Output is correct
66 Correct 2633 ms 204384 KB Output is correct
67 Correct 2557 ms 204384 KB Output is correct