Submission #210353

# Submission time Handle Problem Language Result Execution time Memory
210353 2020-03-17T06:31:45 Z 2qbingxuan Bubble Sort 2 (JOI18_bubblesort2) C++14
0 / 100
41 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,-sgt.query(x,x+1));
        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,-sgt.query(x,x+1));
        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;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Correct 13 ms 12152 KB Output is correct
3 Correct 17 ms 12412 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12280 KB Output is correct
6 Correct 16 ms 12408 KB Output is correct
7 Correct 16 ms 12408 KB Output is correct
8 Correct 16 ms 12408 KB Output is correct
9 Correct 16 ms 12408 KB Output is correct
10 Incorrect 17 ms 12408 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Correct 13 ms 12152 KB Output is correct
3 Correct 17 ms 12412 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12280 KB Output is correct
6 Correct 16 ms 12408 KB Output is correct
7 Correct 16 ms 12408 KB Output is correct
8 Correct 16 ms 12408 KB Output is correct
9 Correct 16 ms 12408 KB Output is correct
10 Incorrect 17 ms 12408 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 13688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Correct 13 ms 12152 KB Output is correct
3 Correct 17 ms 12412 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 16 ms 12280 KB Output is correct
6 Correct 16 ms 12408 KB Output is correct
7 Correct 16 ms 12408 KB Output is correct
8 Correct 16 ms 12408 KB Output is correct
9 Correct 16 ms 12408 KB Output is correct
10 Incorrect 17 ms 12408 KB Output isn't correct
11 Halted 0 ms 0 KB -