답안 #224813

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224813 2020-04-18T23:10:48 Z Bruteforceman Bubble Sort 2 (JOI18_bubblesort2) C++11
60 / 100
9000 ms 93944 KB
#include "bits/stdc++.h"
#include "bubblesort2.h"
using namespace std;
const int maxn = 1000010;
int t[maxn], opt[maxn], pre[maxn];
set <int> cont[maxn];
int idx;

int solve(vector <int> &A) {
    vector <int> cmp (A.size()), pos (A.size());
    for(int i = 0; i < A.size(); i++) cmp[i] = i;
    stable_sort(cmp.begin(), cmp.end(), [&] (int i, int j) { return A[i] < A[j]; });
    for(int i = 0; i < A.size(); i++) pos[cmp[i]] = i;
    int ans = 0;
    for(int i = 0; i < A.size(); i++) {
        ans = max(ans, i - pos[i]);
    }
    return ans;
}

void add(int l, int r, int x) {
    for(int i = l; i <= r; i++) {
        t[i] += x;
    }
}
int getMin() {
    int ans = 0;
    for(int i = 1; i <= idx; i++) {
        ans = max(ans, t[i]);
    }
    return ans;
}

std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
    vector <int> answer (X.size());
    map <int, int> cmp;
    for(int i = 0; i < A.size(); i++) cmp[A[i]];
    for(int i = 0; i < V.size(); i++) cmp[V[i]];
    idx = 0;
    for(auto &i : cmp) {
        i.second = ++idx;
        pre[idx] = t[idx] = opt[idx] = 0;
        cont[idx].clear();
    }
    for(int i = 0; i < A.size(); i++) {
        A[i] = cmp[A[i]];
        pre[A[i]] += 1;
        opt[A[i]] = i + 1;
        cont[A[i]].insert(i + 1);
    }
    for(int i = 1; i <= idx; i++) {
        pre[i] += pre[i - 1];
        t[i] = opt[i] - pre[i];
        cont[i].insert(0);
    }
    for(int i = 0; i < V.size(); i++) {
        int x = X[i];
        int tmp;
        V[i] = cmp[V[i]];

        add(A[x], idx, 1);
        cont[A[x]].erase(x + 1);
        tmp = opt[A[x]];
        opt[A[x]] = *cont[A[x]].rbegin();
        add(A[x], A[x], opt[A[x]] - tmp);


        A[x] = V[i];
        add(A[x], idx, -1);
        cont[A[x]].insert(x + 1);
        tmp = opt[A[x]];
        opt[A[x]] = *cont[A[x]].rbegin();
        add(A[x], A[x], opt[A[x]] - tmp);
        answer[i] = getMin();
    }
    return answer;
}

Compilation message

bubblesort2.cpp: In function 'int solve(std::vector<int>&)':
bubblesort2.cpp:11:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < A.size(); i++) cmp[i] = i;
                    ~~^~~~~~~~~~
bubblesort2.cpp:13:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < A.size(); i++) pos[cmp[i]] = i;
                    ~~^~~~~~~~~~
bubblesort2.cpp:15:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < A.size(); i++) {
                    ~~^~~~~~~~~~
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < A.size(); i++) cmp[A[i]];
                    ~~^~~~~~~~~~
bubblesort2.cpp:38:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < V.size(); i++) cmp[V[i]];
                    ~~^~~~~~~~~~
bubblesort2.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < A.size(); i++) {
                    ~~^~~~~~~~~~
bubblesort2.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < V.size(); i++) {
                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 33 ms 47488 KB Output is correct
3 Correct 46 ms 47872 KB Output is correct
4 Correct 45 ms 47872 KB Output is correct
5 Correct 46 ms 47864 KB Output is correct
6 Correct 46 ms 47864 KB Output is correct
7 Correct 45 ms 47872 KB Output is correct
8 Correct 48 ms 47872 KB Output is correct
9 Correct 52 ms 47992 KB Output is correct
10 Correct 44 ms 47872 KB Output is correct
11 Correct 44 ms 47872 KB Output is correct
12 Correct 44 ms 47872 KB Output is correct
13 Correct 49 ms 47744 KB Output is correct
14 Correct 44 ms 47744 KB Output is correct
15 Correct 46 ms 47868 KB Output is correct
16 Correct 45 ms 47864 KB Output is correct
17 Correct 43 ms 47864 KB Output is correct
18 Correct 42 ms 47744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 33 ms 47488 KB Output is correct
3 Correct 46 ms 47872 KB Output is correct
4 Correct 45 ms 47872 KB Output is correct
5 Correct 46 ms 47864 KB Output is correct
6 Correct 46 ms 47864 KB Output is correct
7 Correct 45 ms 47872 KB Output is correct
8 Correct 48 ms 47872 KB Output is correct
9 Correct 52 ms 47992 KB Output is correct
10 Correct 44 ms 47872 KB Output is correct
11 Correct 44 ms 47872 KB Output is correct
12 Correct 44 ms 47872 KB Output is correct
13 Correct 49 ms 47744 KB Output is correct
14 Correct 44 ms 47744 KB Output is correct
15 Correct 46 ms 47868 KB Output is correct
16 Correct 45 ms 47864 KB Output is correct
17 Correct 43 ms 47864 KB Output is correct
18 Correct 42 ms 47744 KB Output is correct
19 Correct 220 ms 49400 KB Output is correct
20 Correct 264 ms 49656 KB Output is correct
21 Correct 249 ms 49656 KB Output is correct
22 Correct 264 ms 49728 KB Output is correct
23 Correct 234 ms 49400 KB Output is correct
24 Correct 233 ms 49528 KB Output is correct
25 Correct 221 ms 49400 KB Output is correct
26 Correct 244 ms 49272 KB Output is correct
27 Correct 215 ms 49152 KB Output is correct
28 Correct 213 ms 49144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 48896 KB Output is correct
2 Correct 80 ms 50012 KB Output is correct
3 Correct 124 ms 51704 KB Output is correct
4 Correct 111 ms 51576 KB Output is correct
5 Correct 113 ms 51748 KB Output is correct
6 Correct 108 ms 51576 KB Output is correct
7 Correct 107 ms 51576 KB Output is correct
8 Correct 105 ms 51620 KB Output is correct
9 Correct 111 ms 51576 KB Output is correct
10 Correct 96 ms 51704 KB Output is correct
11 Correct 93 ms 51704 KB Output is correct
12 Correct 91 ms 51704 KB Output is correct
13 Correct 89 ms 51704 KB Output is correct
14 Correct 96 ms 51832 KB Output is correct
15 Correct 87 ms 51704 KB Output is correct
16 Correct 87 ms 51752 KB Output is correct
17 Correct 87 ms 51832 KB Output is correct
18 Correct 88 ms 51960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47616 KB Output is correct
2 Correct 33 ms 47488 KB Output is correct
3 Correct 46 ms 47872 KB Output is correct
4 Correct 45 ms 47872 KB Output is correct
5 Correct 46 ms 47864 KB Output is correct
6 Correct 46 ms 47864 KB Output is correct
7 Correct 45 ms 47872 KB Output is correct
8 Correct 48 ms 47872 KB Output is correct
9 Correct 52 ms 47992 KB Output is correct
10 Correct 44 ms 47872 KB Output is correct
11 Correct 44 ms 47872 KB Output is correct
12 Correct 44 ms 47872 KB Output is correct
13 Correct 49 ms 47744 KB Output is correct
14 Correct 44 ms 47744 KB Output is correct
15 Correct 46 ms 47868 KB Output is correct
16 Correct 45 ms 47864 KB Output is correct
17 Correct 43 ms 47864 KB Output is correct
18 Correct 42 ms 47744 KB Output is correct
19 Correct 220 ms 49400 KB Output is correct
20 Correct 264 ms 49656 KB Output is correct
21 Correct 249 ms 49656 KB Output is correct
22 Correct 264 ms 49728 KB Output is correct
23 Correct 234 ms 49400 KB Output is correct
24 Correct 233 ms 49528 KB Output is correct
25 Correct 221 ms 49400 KB Output is correct
26 Correct 244 ms 49272 KB Output is correct
27 Correct 215 ms 49152 KB Output is correct
28 Correct 213 ms 49144 KB Output is correct
29 Correct 45 ms 48896 KB Output is correct
30 Correct 80 ms 50012 KB Output is correct
31 Correct 124 ms 51704 KB Output is correct
32 Correct 111 ms 51576 KB Output is correct
33 Correct 113 ms 51748 KB Output is correct
34 Correct 108 ms 51576 KB Output is correct
35 Correct 107 ms 51576 KB Output is correct
36 Correct 105 ms 51620 KB Output is correct
37 Correct 111 ms 51576 KB Output is correct
38 Correct 96 ms 51704 KB Output is correct
39 Correct 93 ms 51704 KB Output is correct
40 Correct 91 ms 51704 KB Output is correct
41 Correct 89 ms 51704 KB Output is correct
42 Correct 96 ms 51832 KB Output is correct
43 Correct 87 ms 51704 KB Output is correct
44 Correct 87 ms 51752 KB Output is correct
45 Correct 87 ms 51832 KB Output is correct
46 Correct 88 ms 51960 KB Output is correct
47 Execution timed out 9030 ms 93944 KB Time limit exceeded
48 Halted 0 ms 0 KB -