답안 #567797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567797 2022-05-24T08:26:32 Z balbit Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2584 ms 77896 KB
#include <bits/stdc++.h>
#ifndef BALBIT
#include "bubblesort2.h"
#endif // BALBIT
#define int ll
using namespace std;
#define ll long long
#define y1 zck_is_king
#define pii pair<ll, ll>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define RREP(i,n) for (int i = n-1; i>=0; --i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e6+100;

ll tg[maxn*4], mx[maxn*4];

void push(int o, int l, int r){
    if (tg[o]) {
        mx[o] += tg[o];
        if (l!=r) {
            tg[o*2] += tg[o];
            tg[o*2+1] += tg[o];
        }
        tg[o] = 0;
    }
}
void MO(int L, int R, ll v, int o=1, int l=0, int r=maxn-1) {
    push(o,l,r);
    if (l>R || r<L) return;
    if (l >= L && r <= R) {
        tg[o] += v;
        push(o,l,r);
        return;
    }
    int mid = (l+r)/2;
    MO(L,R,v,o*2,l,mid);
    MO(L,R,v,o*2+1,mid+1,r);
    mx[o] = max(mx[o*2], mx[o*2+1]);
}

vector<pii> all;

void upd(int pos, bool add, int idx) {
    bug(pos, add, idx);
    MO(pos+1, maxn-1, add?-1:1);
    MO(pos, pos, (-idx-iinf) * (add?-1:1));
}

vector<signed> countScans(vector<signed> A,vector<signed> X,vector<signed> V){

    int n = SZ(A);
    MO(0, maxn-1, -iinf);

    REP(i, n) {
        all.pb({A[i], i});
    }
    int q = SZ(X);

    REP(i, q) {
        all.pb({V[i], X[i]});
    }

    SORT_UNIQUE(all);

    REP(i,n) {
        upd(lower_bound(ALL(all), pii{A[i], i}) - all.begin(), 1, i);
    }

    vector<signed> re;
    bug(mx[1]);

    REP(rnd, q) {
        int i = X[rnd];
        upd(lower_bound(ALL(all), pii{A[i], i}) - all.begin(), 0,  i);
        A[i] = V[rnd];
        upd(lower_bound(ALL(all), pii{A[i], i}) - all.begin(), 1,  i);

        re.pb(mx[1]);
        bug(mx[1]);
    }
    return re;
}


#ifdef BALBIT
signed main(){
//    countScans({1,1,1,1},{0,2},{3,1});
    countScans({1,2,3,4},{0,2},{3,1});
}
#endif // BALBIT






# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 6 ms 724 KB Output is correct
6 Correct 5 ms 744 KB Output is correct
7 Correct 6 ms 704 KB Output is correct
8 Correct 6 ms 780 KB Output is correct
9 Correct 6 ms 724 KB Output is correct
10 Correct 6 ms 724 KB Output is correct
11 Correct 6 ms 724 KB Output is correct
12 Correct 6 ms 724 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 7 ms 704 KB Output is correct
15 Correct 6 ms 700 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 6 ms 704 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 6 ms 724 KB Output is correct
6 Correct 5 ms 744 KB Output is correct
7 Correct 6 ms 704 KB Output is correct
8 Correct 6 ms 780 KB Output is correct
9 Correct 6 ms 724 KB Output is correct
10 Correct 6 ms 724 KB Output is correct
11 Correct 6 ms 724 KB Output is correct
12 Correct 6 ms 724 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 7 ms 704 KB Output is correct
15 Correct 6 ms 700 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 6 ms 704 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 19 ms 1572 KB Output is correct
20 Correct 23 ms 1704 KB Output is correct
21 Correct 24 ms 1716 KB Output is correct
22 Correct 24 ms 1724 KB Output is correct
23 Correct 21 ms 1560 KB Output is correct
24 Correct 23 ms 1648 KB Output is correct
25 Correct 22 ms 1584 KB Output is correct
26 Correct 24 ms 1592 KB Output is correct
27 Correct 22 ms 1488 KB Output is correct
28 Correct 20 ms 1552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2252 KB Output is correct
2 Correct 88 ms 4764 KB Output is correct
3 Correct 168 ms 7380 KB Output is correct
4 Correct 158 ms 7484 KB Output is correct
5 Correct 153 ms 7376 KB Output is correct
6 Correct 162 ms 7352 KB Output is correct
7 Correct 158 ms 7324 KB Output is correct
8 Correct 161 ms 7356 KB Output is correct
9 Correct 162 ms 7336 KB Output is correct
10 Correct 128 ms 6052 KB Output is correct
11 Correct 125 ms 6140 KB Output is correct
12 Correct 122 ms 6000 KB Output is correct
13 Correct 121 ms 6052 KB Output is correct
14 Correct 131 ms 6056 KB Output is correct
15 Correct 127 ms 6008 KB Output is correct
16 Correct 120 ms 5996 KB Output is correct
17 Correct 141 ms 6020 KB Output is correct
18 Correct 123 ms 5988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 6 ms 724 KB Output is correct
6 Correct 5 ms 744 KB Output is correct
7 Correct 6 ms 704 KB Output is correct
8 Correct 6 ms 780 KB Output is correct
9 Correct 6 ms 724 KB Output is correct
10 Correct 6 ms 724 KB Output is correct
11 Correct 6 ms 724 KB Output is correct
12 Correct 6 ms 724 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 7 ms 704 KB Output is correct
15 Correct 6 ms 700 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 6 ms 704 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 19 ms 1572 KB Output is correct
20 Correct 23 ms 1704 KB Output is correct
21 Correct 24 ms 1716 KB Output is correct
22 Correct 24 ms 1724 KB Output is correct
23 Correct 21 ms 1560 KB Output is correct
24 Correct 23 ms 1648 KB Output is correct
25 Correct 22 ms 1584 KB Output is correct
26 Correct 24 ms 1592 KB Output is correct
27 Correct 22 ms 1488 KB Output is correct
28 Correct 20 ms 1552 KB Output is correct
29 Correct 30 ms 2252 KB Output is correct
30 Correct 88 ms 4764 KB Output is correct
31 Correct 168 ms 7380 KB Output is correct
32 Correct 158 ms 7484 KB Output is correct
33 Correct 153 ms 7376 KB Output is correct
34 Correct 162 ms 7352 KB Output is correct
35 Correct 158 ms 7324 KB Output is correct
36 Correct 161 ms 7356 KB Output is correct
37 Correct 162 ms 7336 KB Output is correct
38 Correct 128 ms 6052 KB Output is correct
39 Correct 125 ms 6140 KB Output is correct
40 Correct 122 ms 6000 KB Output is correct
41 Correct 121 ms 6052 KB Output is correct
42 Correct 131 ms 6056 KB Output is correct
43 Correct 127 ms 6008 KB Output is correct
44 Correct 120 ms 5996 KB Output is correct
45 Correct 141 ms 6020 KB Output is correct
46 Correct 123 ms 5988 KB Output is correct
47 Correct 622 ms 23440 KB Output is correct
48 Correct 2356 ms 71548 KB Output is correct
49 Correct 2579 ms 77588 KB Output is correct
50 Correct 2584 ms 77436 KB Output is correct
51 Correct 2552 ms 77456 KB Output is correct
52 Correct 2530 ms 77484 KB Output is correct
53 Correct 2522 ms 77424 KB Output is correct
54 Correct 2305 ms 77576 KB Output is correct
55 Correct 2507 ms 77896 KB Output is correct
56 Correct 2348 ms 77564 KB Output is correct
57 Correct 2407 ms 77628 KB Output is correct
58 Correct 2253 ms 77536 KB Output is correct
59 Correct 2061 ms 72232 KB Output is correct
60 Correct 2076 ms 72272 KB Output is correct
61 Correct 2029 ms 72252 KB Output is correct
62 Correct 1954 ms 70212 KB Output is correct
63 Correct 1911 ms 70232 KB Output is correct
64 Correct 1977 ms 70024 KB Output is correct
65 Correct 1841 ms 67864 KB Output is correct
66 Correct 1837 ms 67976 KB Output is correct
67 Correct 1819 ms 67792 KB Output is correct