답안 #851762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851762 2023-09-20T14:39:32 Z vjudge1 Bubble Sort 2 (JOI18_bubblesort2) C++17
60 / 100
9000 ms 89120 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int pr=23, s_p=1<<pr, e_p=(1<<(pr+1))-1;
int n;
vector<int>S_sum;

void pre(){
    S_sum.clear();
    S_sum.resize(1<<(pr+1));
}

void update(int ind, int c){
    S_sum[ind]+=c;
    while(ind/=2)
        S_sum[ind]+=c;
}

int get(int id, int u, int v, int l, int r){
    if(l>v || r<u)
        return 0;
    if(l>=u && r<=v)
        return S_sum[id];
    int md=(l+r)/2;
    return get(id*2, u, v, l, md)+get(id*2+1, u, v, md+1, r);
}

vector<int> countScans(vector<int>A, vector<int>X, vector<int>V){
    vector<int>S, All, Cur(A.size());
    n=A.size();
    int q=X.size();
    for(int i=0;i<n;i++){
        All.push_back(A[i]);
    }
    for(int i=0;i<q;i++){
        All.push_back(V[i]);
    }
    sort(all(All));
    int cur=1;
    map<int, int>mp;
    for(int i=0;i<All.size();i++){
        if(i==All.size()-1 || All[i]!=All[i+1])
            mp[All[i]]=cur++;
    }
    for(int i=0;i<n;i++){
        A[i]=mp[A[i]];
    }
    pre();
    for(int i=0;i<n;i++){
        int cur=get(1, s_p+A[i]+1, e_p, s_p, e_p);
        Cur[i]=cur;
        update(s_p+A[i], 1);
    }
    for(int k=0;k<q;k++){
        int ind=X[k], val=mp[V[k]], mx=0, larger=(val>A[ind]);
        for(int i=0;i<ind;i++){
            if(!larger){
                Cur[ind]+=(A[i]>val && A[i]<=A[ind]);
            }
            else{
                Cur[ind]-=(A[i]>A[ind] && A[i]<=val);
            }
        }
        for(int i=ind+1;i<n;i++){
            if(!larger){
                Cur[i]-=(A[ind]>A[i] && val<=A[i]);
            }
            else{
                Cur[i]+=(val>A[i] && A[ind]<=A[i]);
            }
        }
        A[ind]=val;
        for(int i=0;i<n;i++){
            mx=max(mx, Cur[i]);
        }
        S.push_back(mx);
    }
    return S;
}

//int main(){
//    ios_base::sync_with_stdio(0);cin.tie(0);
//    int n, q;
//    cin>>n>>q;
//    vector<int>A(n), X(q), V(q);
//    for(int i=0;i<n;i++){
//        cin>>A[i];
//    }
//    for(int j=0;j<q;j++){
//        cin>>X[j]>>V[j];
//    }
//    vector<int>Ans=countScans(A, X, V);
//    for(int i=0;i<q;i++){
//        cout<<Ans[i]<<endl;
//    }
//}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0;i<All.size();i++){
      |                 ~^~~~~~~~~~~
bubblesort2.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if(i==All.size()-1 || All[i]!=All[i+1])
      |            ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 66136 KB Output is correct
2 Correct 11 ms 66140 KB Output is correct
3 Correct 25 ms 66628 KB Output is correct
4 Correct 22 ms 66396 KB Output is correct
5 Correct 21 ms 66140 KB Output is correct
6 Correct 19 ms 66140 KB Output is correct
7 Correct 19 ms 66140 KB Output is correct
8 Correct 20 ms 66140 KB Output is correct
9 Correct 21 ms 66148 KB Output is correct
10 Correct 18 ms 66136 KB Output is correct
11 Correct 19 ms 66360 KB Output is correct
12 Correct 19 ms 66352 KB Output is correct
13 Correct 18 ms 66392 KB Output is correct
14 Correct 18 ms 66140 KB Output is correct
15 Correct 18 ms 66140 KB Output is correct
16 Correct 17 ms 66140 KB Output is correct
17 Correct 17 ms 66340 KB Output is correct
18 Correct 18 ms 66140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 66136 KB Output is correct
2 Correct 11 ms 66140 KB Output is correct
3 Correct 25 ms 66628 KB Output is correct
4 Correct 22 ms 66396 KB Output is correct
5 Correct 21 ms 66140 KB Output is correct
6 Correct 19 ms 66140 KB Output is correct
7 Correct 19 ms 66140 KB Output is correct
8 Correct 20 ms 66140 KB Output is correct
9 Correct 21 ms 66148 KB Output is correct
10 Correct 18 ms 66136 KB Output is correct
11 Correct 19 ms 66360 KB Output is correct
12 Correct 19 ms 66352 KB Output is correct
13 Correct 18 ms 66392 KB Output is correct
14 Correct 18 ms 66140 KB Output is correct
15 Correct 18 ms 66140 KB Output is correct
16 Correct 17 ms 66140 KB Output is correct
17 Correct 17 ms 66340 KB Output is correct
18 Correct 18 ms 66140 KB Output is correct
19 Correct 165 ms 67036 KB Output is correct
20 Correct 202 ms 67144 KB Output is correct
21 Correct 172 ms 67152 KB Output is correct
22 Correct 198 ms 67136 KB Output is correct
23 Correct 162 ms 67040 KB Output is correct
24 Correct 170 ms 67408 KB Output is correct
25 Correct 149 ms 67244 KB Output is correct
26 Correct 147 ms 66908 KB Output is correct
27 Correct 140 ms 66956 KB Output is correct
28 Correct 147 ms 66904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 66648 KB Output is correct
2 Correct 2899 ms 67672 KB Output is correct
3 Correct 7325 ms 68564 KB Output is correct
4 Correct 7420 ms 68104 KB Output is correct
5 Correct 7193 ms 68520 KB Output is correct
6 Correct 6914 ms 68768 KB Output is correct
7 Correct 6835 ms 68364 KB Output is correct
8 Correct 7009 ms 68520 KB Output is correct
9 Correct 7128 ms 68332 KB Output is correct
10 Correct 5759 ms 68560 KB Output is correct
11 Correct 5404 ms 68596 KB Output is correct
12 Correct 4806 ms 68600 KB Output is correct
13 Correct 5100 ms 68532 KB Output is correct
14 Correct 5285 ms 68308 KB Output is correct
15 Correct 5779 ms 68532 KB Output is correct
16 Correct 7326 ms 68312 KB Output is correct
17 Correct 4840 ms 68100 KB Output is correct
18 Correct 4822 ms 68540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 66136 KB Output is correct
2 Correct 11 ms 66140 KB Output is correct
3 Correct 25 ms 66628 KB Output is correct
4 Correct 22 ms 66396 KB Output is correct
5 Correct 21 ms 66140 KB Output is correct
6 Correct 19 ms 66140 KB Output is correct
7 Correct 19 ms 66140 KB Output is correct
8 Correct 20 ms 66140 KB Output is correct
9 Correct 21 ms 66148 KB Output is correct
10 Correct 18 ms 66136 KB Output is correct
11 Correct 19 ms 66360 KB Output is correct
12 Correct 19 ms 66352 KB Output is correct
13 Correct 18 ms 66392 KB Output is correct
14 Correct 18 ms 66140 KB Output is correct
15 Correct 18 ms 66140 KB Output is correct
16 Correct 17 ms 66140 KB Output is correct
17 Correct 17 ms 66340 KB Output is correct
18 Correct 18 ms 66140 KB Output is correct
19 Correct 165 ms 67036 KB Output is correct
20 Correct 202 ms 67144 KB Output is correct
21 Correct 172 ms 67152 KB Output is correct
22 Correct 198 ms 67136 KB Output is correct
23 Correct 162 ms 67040 KB Output is correct
24 Correct 170 ms 67408 KB Output is correct
25 Correct 149 ms 67244 KB Output is correct
26 Correct 147 ms 66908 KB Output is correct
27 Correct 140 ms 66956 KB Output is correct
28 Correct 147 ms 66904 KB Output is correct
29 Correct 183 ms 66648 KB Output is correct
30 Correct 2899 ms 67672 KB Output is correct
31 Correct 7325 ms 68564 KB Output is correct
32 Correct 7420 ms 68104 KB Output is correct
33 Correct 7193 ms 68520 KB Output is correct
34 Correct 6914 ms 68768 KB Output is correct
35 Correct 6835 ms 68364 KB Output is correct
36 Correct 7009 ms 68520 KB Output is correct
37 Correct 7128 ms 68332 KB Output is correct
38 Correct 5759 ms 68560 KB Output is correct
39 Correct 5404 ms 68596 KB Output is correct
40 Correct 4806 ms 68600 KB Output is correct
41 Correct 5100 ms 68532 KB Output is correct
42 Correct 5285 ms 68308 KB Output is correct
43 Correct 5779 ms 68532 KB Output is correct
44 Correct 7326 ms 68312 KB Output is correct
45 Correct 4840 ms 68100 KB Output is correct
46 Correct 4822 ms 68540 KB Output is correct
47 Execution timed out 9007 ms 89120 KB Time limit exceeded
48 Halted 0 ms 0 KB -