답안 #210313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210313 2020-03-17T03:23:15 Z 2qbingxuan Bubble Sort 2 (JOI18_bubblesort2) C++14
0 / 100
9000 ms 892 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;

void calc(int l, int m, int r) {
    //for(int i = )
}
void CDQ(vector<tuple<int,int,int>> evt) {
    for(int s = 1; s < evt.size(); s *= 2) {
        for(int i = 0; i+s < evt.size(); i++) {
            int j = min(int(evt.size()), i+s*2);
            //calc(evt, i, i+s, j);
        }
    }
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
    int n = A.size(), q = X.size();
    //vector<tuple<int,int,int>> evt;
    /*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]);
    for(int i = 0; i < q; i++) V[i] = get_pos(u, V[i]);
    vector<int> cnt(u.size()+2);
    auto modify = [&](int p, int d) {
        for(; p < cnt.size(); p += p&-p) cnt[p] += d;
    };
    auto query = [&](int p) {
        int res = 0;
        for(; p; p -= p&-p) res += cnt[p];
        return res;
    };
    vector<int> Q;
    for(int i = 0; i < q; i++) {
        A[X[i]-1] = V[i];
        int ans = 0;
        for(int i = n-1; i >= 0; i--) {
            modify(A[i], 1);
            ans = max(ans, query(A[i]-1));
        }
        Q.pb(ans);
    }
    return Q;
}

Compilation message

bubblesort2.cpp: In function 'void CDQ(std::vector<std::tuple<int, int, int> >)':
bubblesort2.cpp:11:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int s = 1; s < evt.size(); s *= 2) {
                    ~~^~~~~~~~~~~~
bubblesort2.cpp:12:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i+s < evt.size(); i++) {
                        ~~~~^~~~~~~~~~~~
bubblesort2.cpp:13:17: warning: unused variable 'j' [-Wunused-variable]
             int j = min(int(evt.size()), i+s*2);
                 ^
bubblesort2.cpp: In lambda function:
bubblesort2.cpp:35:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(; p < cnt.size(); p += p&-p) cnt[p] += d;
               ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9092 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9092 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9075 ms 892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9092 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -