답안 #210351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210351 2020-03-17T06:26:21 Z 2qbingxuan Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
33 ms 13688 KB
#include <bits/stdc++.h>
#define pb emplace_back
#define get_pos(u,x) (lower_bound(begin(u),end(u),x) - begin(u))
using namespace std;
const int N = 1000025, inf = 1e9;

struct Segtree {
    int mx[N<<1], lz[N];
    void init() {
        for(int i = 0; i < N*2; i++) mx[i] = -inf;
        for(int i = 0; i < N; i++) lz[i] = 0;
    }
    void upd(int p, int d) {
        mx[p] += d;
        if(p < N) lz[p] += d;
    }
    void pull(int p) {
        for(; p>1; p>>=1) mx[p>>1] = max(mx[p],mx[p^1]) + lz[p>>1];
    }
    void push(int p) {
        for(int h = __lg(N); h >= 0; h--) {
            int i = p>>h;
            if(!lz[i>>1]) continue;
            upd(i,lz[i>>1]);
            upd(i^1,lz[i>>1]);
            lz[i>>1] = 0;
        }
    }
    void add(int l, int r, int d) {
        int L = l, R = r;
        for(l+=N,r+=N; l<r; l>>=1,r>>=1) {
            if(l&1) upd(l++, d);
            if(r&1) upd(--r, d);
        }
        pull(L+N), pull(R-1+N);
    }
    int query(int l, int r) {
        int res = -inf;
        push(l+N), push(r-1+N);
        for(l+=N,r+=N; l<r; l>>=1,r>>=1) {
            if(l&1) res = max(res, mx[l++]);
            if(r&1) res = max(res, mx[--r]);
        }
        return res;
    }
} sgt;
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
    int n = A.size(), q = X.size();
    /*for(int i = 0; i < n; i++)
        evt.pb(i, i, A[i]);
    for(int i = 0; i < q; i++)
        evt.pb(i+n, X[i]-1, V[i]);
    CDQ(evt);*/
    vector<int> u;
    for(int i = 0; i < n; i++) u.pb(A[i]);
    for(int i = 0; i < q; i++) u.pb(V[i]);
    sort(u.begin(), u.end());
    u.erase(unique(u.begin(), u.end()), u.end());
    for(int i = 0; i < n; i++) A[i] = get_pos(u, A[i]) + 1;
    for(int i = 0; i < q; i++) V[i] = get_pos(u, V[i]) + 1;
    vector<set<int>> idx(u.size()+1);
    vector<int> Q;
    sgt.init();
    auto del = [&](int p, int x) {
        sgt.add(x,x+1,-(*idx[x].rbegin()));
        idx[x].erase(p);
        sgt.add(x,x+1, idx[x].empty() ? -inf : (*idx[x].rbegin()));
        sgt.add(x+1,N,1);
    };
    auto add = [&](int p, int x) {
        sgt.add(x,x+1, idx[x].empty() ? inf : -(*idx[x].rbegin()));
        idx[x].insert(p);
        sgt.add(x,x+1,(*idx[x].rbegin()));
        sgt.add(x+1,N,-1);
    };
    for(int i = 0; i < n; i++) add(i, A[i]);
    for(int i = 0; i < q; i++) {
        // i - #j : v_j < v_i
        del(X[i], A[X[i]]);
        A[X[i]] = V[i];
        add(X[i], A[X[i]]);
        //for(int i = 0; i <= u.size(); i++) sgt.push(i+N), cout << sgt.mx[i+N] << ' ';cout<<'\n';
        Q.pb(sgt.query(0,N));
    }
    return Q;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Correct 14 ms 12156 KB Output is correct
3 Correct 17 ms 12408 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12408 KB Output is correct
6 Correct 17 ms 12408 KB Output is correct
7 Correct 17 ms 12408 KB Output is correct
8 Correct 16 ms 12408 KB Output is correct
9 Correct 17 ms 12408 KB Output is correct
10 Correct 16 ms 12408 KB Output is correct
11 Correct 17 ms 12408 KB Output is correct
12 Correct 16 ms 12408 KB Output is correct
13 Correct 16 ms 12408 KB Output is correct
14 Correct 16 ms 12408 KB Output is correct
15 Correct 16 ms 12408 KB Output is correct
16 Correct 16 ms 12408 KB Output is correct
17 Correct 19 ms 12408 KB Output is correct
18 Correct 15 ms 12408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Correct 14 ms 12156 KB Output is correct
3 Correct 17 ms 12408 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12408 KB Output is correct
6 Correct 17 ms 12408 KB Output is correct
7 Correct 17 ms 12408 KB Output is correct
8 Correct 16 ms 12408 KB Output is correct
9 Correct 17 ms 12408 KB Output is correct
10 Correct 16 ms 12408 KB Output is correct
11 Correct 17 ms 12408 KB Output is correct
12 Correct 16 ms 12408 KB Output is correct
13 Correct 16 ms 12408 KB Output is correct
14 Correct 16 ms 12408 KB Output is correct
15 Correct 16 ms 12408 KB Output is correct
16 Correct 16 ms 12408 KB Output is correct
17 Correct 19 ms 12408 KB Output is correct
18 Correct 15 ms 12408 KB Output is correct
19 Correct 29 ms 13304 KB Output is correct
20 Correct 31 ms 13432 KB Output is correct
21 Correct 31 ms 13432 KB Output is correct
22 Correct 31 ms 13432 KB Output is correct
23 Correct 30 ms 13432 KB Output is correct
24 Correct 29 ms 13432 KB Output is correct
25 Correct 29 ms 13308 KB Output is correct
26 Correct 30 ms 13436 KB Output is correct
27 Correct 29 ms 13304 KB Output is correct
28 Correct 28 ms 13304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 13688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Correct 14 ms 12156 KB Output is correct
3 Correct 17 ms 12408 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12408 KB Output is correct
6 Correct 17 ms 12408 KB Output is correct
7 Correct 17 ms 12408 KB Output is correct
8 Correct 16 ms 12408 KB Output is correct
9 Correct 17 ms 12408 KB Output is correct
10 Correct 16 ms 12408 KB Output is correct
11 Correct 17 ms 12408 KB Output is correct
12 Correct 16 ms 12408 KB Output is correct
13 Correct 16 ms 12408 KB Output is correct
14 Correct 16 ms 12408 KB Output is correct
15 Correct 16 ms 12408 KB Output is correct
16 Correct 16 ms 12408 KB Output is correct
17 Correct 19 ms 12408 KB Output is correct
18 Correct 15 ms 12408 KB Output is correct
19 Correct 29 ms 13304 KB Output is correct
20 Correct 31 ms 13432 KB Output is correct
21 Correct 31 ms 13432 KB Output is correct
22 Correct 31 ms 13432 KB Output is correct
23 Correct 30 ms 13432 KB Output is correct
24 Correct 29 ms 13432 KB Output is correct
25 Correct 29 ms 13308 KB Output is correct
26 Correct 30 ms 13436 KB Output is correct
27 Correct 29 ms 13304 KB Output is correct
28 Correct 28 ms 13304 KB Output is correct
29 Incorrect 33 ms 13688 KB Output isn't correct
30 Halted 0 ms 0 KB -