답안 #204177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204177 2020-02-24T21:26:52 Z DS007 Bubble Sort 2 (JOI18_bubblesort2) C++14
0 / 100
88 ms 96120 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6;
map<int, int> m;
int t[N * 8], lazy[N * 8];
multiset<int> pos[N];

void push_down(int v) {
    t[v] += lazy[v];
    lazy[v * 2] += lazy[v];
    lazy[v * 2 + 1] += lazy[v];
    lazy[v] = 0;
}

void update(int v, int l, int r, int tl, int tr, int val) {
    if (v >= N * 4) for(;;);
    if (tl > tr)
        return;
    push_down(v); push_down(v * 2); push_down(v * 2 + 1);
    if (l == tl && r == tr) {
        lazy[v] += val;
        push_down(v);
        return;
    }

    int mid = (l + r) / 2;
    update(v * 2, l, mid, tl, min(mid, tr), val);
    update(v * 2 + 1, mid + 1, r, max(tl, mid + 1), tr, val);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}

void add(int e, int i) {
    update(1, 0, N - 1, e, N - 1, -1);
    int dif = pos[e].empty() ? 0 : *pos[e].rbegin();
    pos[e].insert(i);
    dif = *pos[e].rbegin() - dif;
    update(1, 0, N - 1, e, e, dif);
}

void remove(int e, int i) {
    update(1, 0, N - 1, e, N - 1, 1);
    int dif = *pos[e].rbegin();
    pos[e].erase(i);
    dif = pos[e].empty() ? -dif : *pos[e].rbegin() - dif;
    update(1, 0, N - 1, e, e, dif);
}

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
    for (auto &i : a) m[i] = 0;
    for (auto &i : v) m[i] = 0;
    int cur = 0;
    for (auto &i : m) i.second = cur++;

    for (int i = 0; i < a.size(); i++) {
        a[i] = m[a[i]];
        add(a[i], i + 1);
    }

    vector<int> ans;
    for (int i = 0; i < x.size(); i++) {
        v[i] = m[v[i]];
        remove(a[x[i]], x[i] + 1);
        add(v[i], x[i] + 1);
        ans.push_back(t[1]);
        // cout << t[1] << "\n";
    }

    return ans;
}

/*signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    countScans({1, 2, 3, 4}, {0, 2}, {3, 1});
}*/

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:55:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i++) {
                     ~~^~~~~~~~~~
bubblesort2.cpp:61:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < x.size(); i++) {
                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 88 ms 96120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 88 ms 96120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 49016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 88 ms 96120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -