Submission #210809

# Submission time Handle Problem Language Result Execution time Memory
210809 2020-03-18T11:18:10 Z 2qbingxuan Bubble Sort 2 (JOI18_bubblesort2) C++14
0 / 100
9000 ms 1136 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;
typedef long long ll;
const ll N = 500025, INF = 1e18;

struct Segtree {
    int mx[N<<1],lz[N],n;
    void upd(int p, ll 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, ll 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 = -1e9;
        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;
    }
    /*void dbg() {
        cout << "-------\n";
        for(int i = 0; i < 10; i++) {
            push(i+N);
            cout << mx[i+N] << ' ';
        }
        cout << '\n';
    }*/
} sgt;

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
    int n = A.size(), q = X.size();
    vector<ll> u;
    for(int i = 0; i < n; i++) u.pb(A[i] * N + i);
    for(int i = 0; i < q; i++) u.pb(V[i] * N + X[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] * N + i);
    for(int i = 0; i < q; i++) V[i] = get_pos(u, V[i] * N + X[i]);
    vector<int> Q;
    //sgt.init();
    for(int i = 0; i < n; i++) {
        sgt.add(A[i], A[i]+1, i);
        sgt.add(A[i]+1, N, -1);
    }
    for(int i = 0; i < q; i++) {
        int x = X[i];
        sgt.add(A[x],A[x]+1, -x);
        sgt.add(A[x]+1, u.size(), 1);
        A[x] = V[i];
        sgt.add(A[x],A[x]+1, x);
        sgt.add(A[x]+1, u.size(), -1);
        //sgt.dbg();
        Q.pb(sgt.query(0, u.size()));
    }
    return Q;
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 9064 ms 1136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -