답안 #158970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158970 2019-10-19T17:11:50 Z janchomath Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
4386 ms 236728 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define N 500005
using namespace std;
ll n,m,pown=1,a[N],b[N],c[N],t[10*N],save[10*N],l,r,ad;
vector<ll>v;
map<ll,ll>mp;
set<ll>st[3 * N];
void updd(ll x){
    if(!x)return;
    t[x] = max(t[2 * x] , t[2 * x + 1]);
    updd(x / 2);
}
void upd(ll x,ll L,ll R){
    if(L > r || R < l)return;
    if(L >= l && R <= r){
        save[x] += ad;
        t[x] += ad;
        return;
    }
    if(save[x]){
        save[2 * x] += save[x];
        save[2 * x + 1] += save[x];
        t[2 * x] += save[x];
        t[2 * x + 1] += save[x];
        save[x] = 0;
    }
    upd(2 * x, L , (L + R) / 2);
    upd(2 * x + 1 , (L + R) / 2 + 1, R);
    t[x] = max(t[2 * x] , t[2 * x + 1]);
}
vector<int> countScans(vector<int>ff ,vector<int>uu,vector<int>vv){
    n = ff.size();
    m = uu.size();
    for(int i=1; i<=n; i++)
        a[i] = ff[i - 1],
        v.pb(a[i]);
    for(int i=1; i<=m; i++){
        b[i] = uu[i - 1] + 1;
        c[i] = vv[i - 1];
        v.pb(c[i]);
    }
    
    sort(v.begin() , v.end());
    ll p = 0;
    for(int i=0; i<v.size(); i++){
        if(!i || v[i] != v[i - 1])p++;
        mp[v[i]] = p;
    }
    
    for(int i=1; i<=n; i++){
        a[i] = mp[a[i]];
        st[a[i]].insert(-i);
    }
    for(int i=1; i<=m; i++)
        c[i] = mp[c[i]];
    
    while(pown <= n + m)
        pown *= 2;
    for(int i=1; i<=n; i++){
        t[pown + a[i] - 1] = -(*st[a[i]].begin());
        save[pown + a[i] - 1] = -(*st[a[i]].begin());
        updd((pown + a[i] - 1) / 2);
    }
    for(int i=1; i<=n; i++){
        l = a[i],r = n + m;
        ad = -1;
        upd(1 , 1 , pown);
    }
    vector<int>ans;
    
    for(int q=1; q<=m; q++){
        ll x,y;
        x = b[q];
        y = c[q];
        l = a[x],r = a[x];
        ad = (*st[a[x]].begin());
        st[a[x]].erase(st[a[x]].find(-x));
        if(st[a[x]].size())ad -= (*st[a[x]].begin());
        upd(1 , 1 , pown);
        ad = 1;
        l = a[x],r = n + m;
        upd(1 , 1 , pown);
        a[x] = y;
        l = a[x],r = a[x];
        ad = (*st[a[x]].begin());
        st[a[x]].insert(-x);
        ad -= (*st[a[x]].begin());
        upd(1 , 1 , pown);
        ad = -1;
        l = a[x] , r = n + m;
        upd(1 , 1 , pown);
        ans.pb(t[1]);
        //cout << t[1] << " ";
    }
    return ans;
}
/*
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> m;
    vector<ll>aa,xx,yy;
    for(int i=1; i<=n; i++){
        ll x;
        cin >> x;
        aa.pb(x);
    }
    for(int i=1; i<=m; i++){
        ll x,y;
        cin >> x >> y;
        xx.pb(x);
        yy.pb(y);
    }
    
    countScans(aa , xx , yy);
    
    
    return 0;
}
*/

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:49:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<v.size(); i++){
                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 71032 KB Output is correct
2 Correct 69 ms 71160 KB Output is correct
3 Correct 73 ms 71544 KB Output is correct
4 Correct 73 ms 71452 KB Output is correct
5 Correct 74 ms 71416 KB Output is correct
6 Correct 73 ms 71412 KB Output is correct
7 Correct 72 ms 71416 KB Output is correct
8 Correct 73 ms 71416 KB Output is correct
9 Correct 72 ms 71580 KB Output is correct
10 Correct 74 ms 71412 KB Output is correct
11 Correct 72 ms 71380 KB Output is correct
12 Correct 83 ms 71380 KB Output is correct
13 Correct 73 ms 71396 KB Output is correct
14 Correct 72 ms 71416 KB Output is correct
15 Correct 72 ms 71416 KB Output is correct
16 Correct 72 ms 71416 KB Output is correct
17 Correct 71 ms 71416 KB Output is correct
18 Correct 71 ms 71416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 71032 KB Output is correct
2 Correct 69 ms 71160 KB Output is correct
3 Correct 73 ms 71544 KB Output is correct
4 Correct 73 ms 71452 KB Output is correct
5 Correct 74 ms 71416 KB Output is correct
6 Correct 73 ms 71412 KB Output is correct
7 Correct 72 ms 71416 KB Output is correct
8 Correct 73 ms 71416 KB Output is correct
9 Correct 72 ms 71580 KB Output is correct
10 Correct 74 ms 71412 KB Output is correct
11 Correct 72 ms 71380 KB Output is correct
12 Correct 83 ms 71380 KB Output is correct
13 Correct 73 ms 71396 KB Output is correct
14 Correct 72 ms 71416 KB Output is correct
15 Correct 72 ms 71416 KB Output is correct
16 Correct 72 ms 71416 KB Output is correct
17 Correct 71 ms 71416 KB Output is correct
18 Correct 71 ms 71416 KB Output is correct
19 Correct 94 ms 73180 KB Output is correct
20 Correct 94 ms 73436 KB Output is correct
21 Correct 94 ms 73608 KB Output is correct
22 Correct 95 ms 73596 KB Output is correct
23 Correct 91 ms 73336 KB Output is correct
24 Correct 93 ms 73436 KB Output is correct
25 Correct 91 ms 73208 KB Output is correct
26 Correct 93 ms 73208 KB Output is correct
27 Correct 90 ms 73080 KB Output is correct
28 Correct 106 ms 73080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 73008 KB Output is correct
2 Correct 148 ms 75180 KB Output is correct
3 Correct 216 ms 77392 KB Output is correct
4 Correct 220 ms 77420 KB Output is correct
5 Correct 213 ms 77384 KB Output is correct
6 Correct 212 ms 77408 KB Output is correct
7 Correct 212 ms 77548 KB Output is correct
8 Correct 211 ms 77424 KB Output is correct
9 Correct 210 ms 77548 KB Output is correct
10 Correct 190 ms 77596 KB Output is correct
11 Correct 191 ms 77548 KB Output is correct
12 Correct 189 ms 77564 KB Output is correct
13 Correct 187 ms 77488 KB Output is correct
14 Correct 190 ms 77548 KB Output is correct
15 Correct 186 ms 77420 KB Output is correct
16 Correct 180 ms 77548 KB Output is correct
17 Correct 181 ms 77548 KB Output is correct
18 Correct 177 ms 77548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 71032 KB Output is correct
2 Correct 69 ms 71160 KB Output is correct
3 Correct 73 ms 71544 KB Output is correct
4 Correct 73 ms 71452 KB Output is correct
5 Correct 74 ms 71416 KB Output is correct
6 Correct 73 ms 71412 KB Output is correct
7 Correct 72 ms 71416 KB Output is correct
8 Correct 73 ms 71416 KB Output is correct
9 Correct 72 ms 71580 KB Output is correct
10 Correct 74 ms 71412 KB Output is correct
11 Correct 72 ms 71380 KB Output is correct
12 Correct 83 ms 71380 KB Output is correct
13 Correct 73 ms 71396 KB Output is correct
14 Correct 72 ms 71416 KB Output is correct
15 Correct 72 ms 71416 KB Output is correct
16 Correct 72 ms 71416 KB Output is correct
17 Correct 71 ms 71416 KB Output is correct
18 Correct 71 ms 71416 KB Output is correct
19 Correct 94 ms 73180 KB Output is correct
20 Correct 94 ms 73436 KB Output is correct
21 Correct 94 ms 73608 KB Output is correct
22 Correct 95 ms 73596 KB Output is correct
23 Correct 91 ms 73336 KB Output is correct
24 Correct 93 ms 73436 KB Output is correct
25 Correct 91 ms 73208 KB Output is correct
26 Correct 93 ms 73208 KB Output is correct
27 Correct 90 ms 73080 KB Output is correct
28 Correct 106 ms 73080 KB Output is correct
29 Correct 99 ms 73008 KB Output is correct
30 Correct 148 ms 75180 KB Output is correct
31 Correct 216 ms 77392 KB Output is correct
32 Correct 220 ms 77420 KB Output is correct
33 Correct 213 ms 77384 KB Output is correct
34 Correct 212 ms 77408 KB Output is correct
35 Correct 212 ms 77548 KB Output is correct
36 Correct 211 ms 77424 KB Output is correct
37 Correct 210 ms 77548 KB Output is correct
38 Correct 190 ms 77596 KB Output is correct
39 Correct 191 ms 77548 KB Output is correct
40 Correct 189 ms 77564 KB Output is correct
41 Correct 187 ms 77488 KB Output is correct
42 Correct 190 ms 77548 KB Output is correct
43 Correct 186 ms 77420 KB Output is correct
44 Correct 180 ms 77548 KB Output is correct
45 Correct 181 ms 77548 KB Output is correct
46 Correct 177 ms 77548 KB Output is correct
47 Correct 1028 ms 120748 KB Output is correct
48 Correct 3713 ms 221528 KB Output is correct
49 Correct 4171 ms 236596 KB Output is correct
50 Correct 4122 ms 236476 KB Output is correct
51 Correct 4386 ms 236552 KB Output is correct
52 Correct 3975 ms 236552 KB Output is correct
53 Correct 4029 ms 236628 KB Output is correct
54 Correct 3691 ms 236672 KB Output is correct
55 Correct 3932 ms 236440 KB Output is correct
56 Correct 3834 ms 236728 KB Output is correct
57 Correct 3968 ms 236572 KB Output is correct
58 Correct 3850 ms 236400 KB Output is correct
59 Correct 3317 ms 223672 KB Output is correct
60 Correct 3276 ms 223820 KB Output is correct
61 Correct 3262 ms 223576 KB Output is correct
62 Correct 3199 ms 217808 KB Output is correct
63 Correct 3238 ms 217676 KB Output is correct
64 Correct 3238 ms 217676 KB Output is correct
65 Correct 3042 ms 211552 KB Output is correct
66 Correct 3112 ms 211744 KB Output is correct
67 Correct 3159 ms 211828 KB Output is correct