Submission #58119

# Submission time Handle Problem Language Result Execution time Memory
58119 2018-07-16T21:44:07 Z paulica Bubble Sort 2 (JOI18_bubblesort2) C++14
0 / 100
207 ms 110688 KB
#include "bubblesort2.h"

#include <bits/stdc++.h>
using namespace std;

const int Off = 1 << 20;

struct SegTree {
    int a[2 * Off], lazy[2 * Off];
    set<int> inds[Off];

    SegTree() {
        for (int i = 1; i < 2 * Off; i++) a[i] = -1e9;
        for (int i = 0; i < Off; i++) inds[i].insert(-1e9);
    }

    void propagate(int i) {
        a[i] += lazy[i];

        if (i < Off) {
            lazy[2 * i] += lazy[i];
            lazy[2 * i + 1] += lazy[i];
        }

        lazy[i] = 0;
    }

    void update_path(int j, int i = 1, int lo = 0, int hi = Off) {
        propagate(i);
        if (lo + 1 == hi) return;

        int mid = (lo + hi) / 2;
        if (j < mid) update_path(j, 2 * i, lo, mid);
        else update_path(j, 2 * i + 1, mid, hi);

        a[i] = max(a[2 * i], a[2 * i + 1]);
    }

    void update_inds(int i, int ind, bool add) {
        a[i + Off] -= *inds[i].rbegin();
        
        if (add) inds[i].insert(ind);
        else inds[i].erase(ind);

        a[i + Off] += *inds[i].rbegin();
        
        update_path(i);
    }

    void update_segment(int l, int r, int val, int i = 1, int lo = 0, int hi = Off) {
        if (r <= lo || hi <= l) return;
        if (l <= lo && hi <= r) {
            lazy[i] += val;
            propagate(i);
        } else {
            propagate(i);

            int mid = (lo + hi) / 2;
            update_segment(l, r, val, 2 * i, lo, mid);
            update_segment(l, r, val, 2 * i + 1, mid, hi);

            a[i] = max(a[2 * i], a[2 * i + 1]);
        }
    }

    void update_segment(int i, bool add) {
        if (add) update_segment(i + 1, Off, -1);
        else update_segment(i + 1, Off, 1);
    }

    int query() {
        propagate(1);
        return a[1];
    }
} T;

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v){
    int n = a.size(), q = x.size();
    vector<int> answer(q);

    vector<tuple<int, int, int>> val;
    map<int, int> compress;

    for (int i = 0; i < n; i++) val.push_back(make_tuple(a[i], i, i));
    for (int i = 0; i < q; i++) val.push_back(make_tuple(v[i], x[i], i + n));

    sort(val.begin(), val.end());

    for (int i = 0; i < (int)val.size(); i++)
        compress[get<2>(val[i])] = i;

    for (int i = 0; i < n; i++) {
        int t = compress[i];

        T.update_inds(t, i, true);
        T.update_segment(t, true);
    }

    for (int i = 0; i < n; i++) a[i] = i;

    for (int i = 0; i < q; i++) {
        int t = compress[a[x[i]]];

        T.update_inds(t, x[i], false);
        T.update_segment(t, false);

        a[x[i]] = i + n;
        t = compress[i + n];

        T.update_inds(t, x[i], true);
        T.update_segment(t, true);

        answer[i] = T.query();
    }

    return answer;
}
# Verdict Execution time Memory Grader output
1 Incorrect 161 ms 107128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 161 ms 107128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 207 ms 110688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 161 ms 107128 KB Output isn't correct
2 Halted 0 ms 0 KB -