답안 #445504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445504 2021-07-18T10:58:11 Z cpp219 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2910 ms 129652 KB
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e6 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;

set<ll> s[N];
ll n,Q,st[4*N],a[N],cnt[N],sz = N - 1,lazy[4*N];

void Pass(ll id){
    ll t = lazy[id]; lazy[id] = 0;
    st[id*2] += t; lazy[id*2] += t;
    st[id*2 + 1] += t; lazy[id*2 + 1] += t;
}

void upd(ll id,ll l,ll r,ll u,ll v,ll val){
    if (v < l||r < u) return;
    if (u <= l&&r <= v){
        if (u == v) st[id] = val;
        else st[id] += val,lazy[id] += val;
        return;
    }
    ll mid = (l + r)/2; Pass(id);
    upd(id*2,l,mid,u,v,val); upd(id*2 + 1,mid + 1,r,u,v,val);
    st[id] = max(st[id*2],st[id*2 + 1]);
}

vector<ll> v;
LL q[N];

ll Find(ll x){
    return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}

void compress(){
    sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
    for (ll i = 1;i <= n;i++) a[i] = Find(a[i]);
    for (ll i = 1;i <= Q;i++) q[i].sc = Find(q[i].sc);
}

ll bit[N];
void updBIT(ll p,ll val){
    for (ll i = p;i < N;i += i & -i) bit[i] += val;
}

ll Get(ll p){
    ll res = 0;
    for (ll i = p;i > 0;i -= i & -i) res += bit[i];
    return res;
}

void Reupdate(ll p){
    if (s[p].empty()) upd(1,1,sz,p,p,-inf);
    else{
        ll mx = *s[p].rbegin(); upd(1,1,sz,p,p,mx - Get(p));
    }
}

vector<ll> countScans(vector<ll> A,vector<ll> X,vector<ll> V){
    vector<ll> ans; ll kq;
    n = A.size(); Q = X.size();
    for (ll i = 1;i <= Q;i++){
        q[i] = {X[i - 1] + 1,V[i - 1]}; v.push_back(V[i - 1]);
    }
    for (ll i = 1;i <= n;i++) a[i] = A[i - 1],v.push_back(a[i]);
    compress();
    for (ll i = 1;i <= n;i++) s[a[i]].insert(i),updBIT(a[i],1);
    for (ll i = 1;i <= n;i++) Reupdate(a[i]);

    for (ll i = 1;i <= Q;i++){
        ll p1 = a[q[i].fs],p2 = q[i].sc;
        updBIT(p1,-1); updBIT(p2,1); a[q[i].fs] = p2;
        upd(1,1,sz,p1,sz,1); upd(1,1,sz,p2,sz,-1); //cout<<p1; exit(0);
        s[p1].erase(q[i].fs); s[p2].insert(q[i].fs); Reupdate(p1); Reupdate(p2);
        //upd(1,1,sz,1,1,-inf);
        //cout<<st[1]; exit(0);
        //cout<<*s[p2].rbegin() - Get(p2); exit(0);

        ans.push_back(st[1]);
    }
    return ans;
}

Compilation message

bubblesort2.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
bubblesort2.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
bubblesort2.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:69:24: warning: unused variable 'kq' [-Wunused-variable]
   69 |     vector<ll> ans; ll kq;
      |                        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47436 KB Output is correct
2 Correct 27 ms 47564 KB Output is correct
3 Correct 32 ms 47772 KB Output is correct
4 Correct 32 ms 47744 KB Output is correct
5 Correct 39 ms 47736 KB Output is correct
6 Correct 32 ms 47864 KB Output is correct
7 Correct 31 ms 47684 KB Output is correct
8 Correct 31 ms 47692 KB Output is correct
9 Correct 31 ms 47664 KB Output is correct
10 Correct 31 ms 47648 KB Output is correct
11 Correct 32 ms 47684 KB Output is correct
12 Correct 31 ms 47652 KB Output is correct
13 Correct 31 ms 47648 KB Output is correct
14 Correct 30 ms 47736 KB Output is correct
15 Correct 30 ms 47704 KB Output is correct
16 Correct 31 ms 47692 KB Output is correct
17 Correct 31 ms 47692 KB Output is correct
18 Correct 31 ms 47680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47436 KB Output is correct
2 Correct 27 ms 47564 KB Output is correct
3 Correct 32 ms 47772 KB Output is correct
4 Correct 32 ms 47744 KB Output is correct
5 Correct 39 ms 47736 KB Output is correct
6 Correct 32 ms 47864 KB Output is correct
7 Correct 31 ms 47684 KB Output is correct
8 Correct 31 ms 47692 KB Output is correct
9 Correct 31 ms 47664 KB Output is correct
10 Correct 31 ms 47648 KB Output is correct
11 Correct 32 ms 47684 KB Output is correct
12 Correct 31 ms 47652 KB Output is correct
13 Correct 31 ms 47648 KB Output is correct
14 Correct 30 ms 47736 KB Output is correct
15 Correct 30 ms 47704 KB Output is correct
16 Correct 31 ms 47692 KB Output is correct
17 Correct 31 ms 47692 KB Output is correct
18 Correct 31 ms 47680 KB Output is correct
19 Correct 47 ms 48584 KB Output is correct
20 Correct 50 ms 48740 KB Output is correct
21 Correct 55 ms 48684 KB Output is correct
22 Correct 50 ms 48708 KB Output is correct
23 Correct 50 ms 48576 KB Output is correct
24 Correct 50 ms 48576 KB Output is correct
25 Correct 50 ms 48560 KB Output is correct
26 Correct 50 ms 48580 KB Output is correct
27 Correct 49 ms 48544 KB Output is correct
28 Correct 48 ms 48564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 49272 KB Output is correct
2 Correct 116 ms 50812 KB Output is correct
3 Correct 181 ms 52300 KB Output is correct
4 Correct 182 ms 52408 KB Output is correct
5 Correct 176 ms 52412 KB Output is correct
6 Correct 183 ms 52996 KB Output is correct
7 Correct 183 ms 53028 KB Output is correct
8 Correct 184 ms 53020 KB Output is correct
9 Correct 187 ms 52972 KB Output is correct
10 Correct 162 ms 52964 KB Output is correct
11 Correct 184 ms 53052 KB Output is correct
12 Correct 164 ms 52992 KB Output is correct
13 Correct 157 ms 53048 KB Output is correct
14 Correct 159 ms 52964 KB Output is correct
15 Correct 161 ms 52924 KB Output is correct
16 Correct 155 ms 53044 KB Output is correct
17 Correct 151 ms 53036 KB Output is correct
18 Correct 154 ms 53004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47436 KB Output is correct
2 Correct 27 ms 47564 KB Output is correct
3 Correct 32 ms 47772 KB Output is correct
4 Correct 32 ms 47744 KB Output is correct
5 Correct 39 ms 47736 KB Output is correct
6 Correct 32 ms 47864 KB Output is correct
7 Correct 31 ms 47684 KB Output is correct
8 Correct 31 ms 47692 KB Output is correct
9 Correct 31 ms 47664 KB Output is correct
10 Correct 31 ms 47648 KB Output is correct
11 Correct 32 ms 47684 KB Output is correct
12 Correct 31 ms 47652 KB Output is correct
13 Correct 31 ms 47648 KB Output is correct
14 Correct 30 ms 47736 KB Output is correct
15 Correct 30 ms 47704 KB Output is correct
16 Correct 31 ms 47692 KB Output is correct
17 Correct 31 ms 47692 KB Output is correct
18 Correct 31 ms 47680 KB Output is correct
19 Correct 47 ms 48584 KB Output is correct
20 Correct 50 ms 48740 KB Output is correct
21 Correct 55 ms 48684 KB Output is correct
22 Correct 50 ms 48708 KB Output is correct
23 Correct 50 ms 48576 KB Output is correct
24 Correct 50 ms 48576 KB Output is correct
25 Correct 50 ms 48560 KB Output is correct
26 Correct 50 ms 48580 KB Output is correct
27 Correct 49 ms 48544 KB Output is correct
28 Correct 48 ms 48564 KB Output is correct
29 Correct 52 ms 49272 KB Output is correct
30 Correct 116 ms 50812 KB Output is correct
31 Correct 181 ms 52300 KB Output is correct
32 Correct 182 ms 52408 KB Output is correct
33 Correct 176 ms 52412 KB Output is correct
34 Correct 183 ms 52996 KB Output is correct
35 Correct 183 ms 53028 KB Output is correct
36 Correct 184 ms 53020 KB Output is correct
37 Correct 187 ms 52972 KB Output is correct
38 Correct 162 ms 52964 KB Output is correct
39 Correct 184 ms 53052 KB Output is correct
40 Correct 164 ms 52992 KB Output is correct
41 Correct 157 ms 53048 KB Output is correct
42 Correct 159 ms 52964 KB Output is correct
43 Correct 161 ms 52924 KB Output is correct
44 Correct 155 ms 53044 KB Output is correct
45 Correct 151 ms 53036 KB Output is correct
46 Correct 154 ms 53004 KB Output is correct
47 Correct 696 ms 72440 KB Output is correct
48 Correct 2644 ms 121808 KB Output is correct
49 Correct 2903 ms 129480 KB Output is correct
50 Correct 2892 ms 129544 KB Output is correct
51 Correct 2910 ms 129464 KB Output is correct
52 Correct 2867 ms 129420 KB Output is correct
53 Correct 2901 ms 129556 KB Output is correct
54 Correct 2642 ms 129648 KB Output is correct
55 Correct 2754 ms 129652 KB Output is correct
56 Correct 2654 ms 129528 KB Output is correct
57 Correct 2748 ms 129632 KB Output is correct
58 Correct 2601 ms 129632 KB Output is correct
59 Correct 2405 ms 125992 KB Output is correct
60 Correct 2392 ms 126076 KB Output is correct
61 Correct 2403 ms 125860 KB Output is correct
62 Correct 2239 ms 124416 KB Output is correct
63 Correct 2289 ms 124472 KB Output is correct
64 Correct 2435 ms 124452 KB Output is correct
65 Correct 2220 ms 123052 KB Output is correct
66 Correct 2124 ms 123080 KB Output is correct
67 Correct 2169 ms 123048 KB Output is correct