Submission #278070

# Submission time Handle Problem Language Result Execution time Memory
278070 2020-08-21T09:45:10 Z Revo7 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
7125 ms 215928 KB
#include "bubblesort2.h"
#include<bits/stdc++.h>
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#define ll long long
#define mid (l+r)/2

using namespace std;
const int maxn=1e6+100;
vector<int>a,pos,val,ans;
int cnt=0;
map<int,int>ha;
set<int>id[maxn];
int st[4*maxn],lazy[4*maxn];

void upd(int i,int l,int r,int ql,int qr,int del){
    if(lazy[i]){
        st[i]+=lazy[i];
        if(l!=r){
            lazy[left]+=lazy[i];
            lazy[righ]+=lazy[i];
        }
        lazy[i]=0;
    }
    if(r<ql||l>qr)return;
    if(l>=ql&&r<=qr){
        st[i]+=del;
        if(l!=r){
            lazy[left]+=del;
            lazy[righ]+=del;
        }
        return;
    }
    upd(left,l,mid,ql,qr,del);
    upd(righ,mid+1,r,ql,qr,del);
    st[i]=max(st[left],st[righ]);
}

void rem(int i,int x){
    upd(0,0,cnt-1,x,cnt-1,1);
    if(i==*id[x].rbegin()){
        auto it=id[x].end();
        it--;
        int del=-*it;
        it--;
        del+=*it;
        upd(0,0,cnt-1,x,x,del);
    }
    id[x].erase(i);
}

void add(int i,int x){
    upd(0,0,cnt-1,x,cnt-1,-1);
    if(i>*id[x].rbegin()){
        upd(0,0,cnt-1,x,x,i-*id[x].rbegin());
    }
    id[x].insert(i);
    a[i]=x;
}
void solve(){
    for(auto x:a)ha[x]=1;
    for(auto x:val)ha[x]=1;
    for(auto &x:ha){
        x.second=cnt++;
    }
    //for(auto x:a)cout<<ha[x]<<' ';cout<<endl;

    for(int i=0;i<cnt;i++){
        id[i].insert(-maxn);
    }
    //cout<<cnt<<endl;
    for(int i=0;i<a.size();i++){
        a[i]=ha[a[i]];
        id[a[i]].insert(i);
        upd(0,0,cnt-1,a[i],cnt-1,-1);
    }
    //cout<<"hello"<<endl;
    for(int i=0;i<cnt;i++){
        upd(0,0,cnt-1,i,i,*id[i].rbegin());
    }

    for(int q=0;q<pos.size();q++){
        rem(pos[q],a[pos[q]]);
        add(pos[q],ha[val[q]]);
        ans.pb(st[0]+1);
    }
}



vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
    a=A;
    pos=X;
    val=V;
    solve();
	return ans;
}
/*
4 2
1 2 3 4
0 3
2 1
*/

Compilation message

bubblesort2.cpp: In function 'void solve()':
bubblesort2.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
bubblesort2.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int q=0;q<pos.size();q++){
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47488 KB Output is correct
2 Correct 33 ms 47608 KB Output is correct
3 Correct 37 ms 48000 KB Output is correct
4 Correct 37 ms 47968 KB Output is correct
5 Correct 40 ms 47992 KB Output is correct
6 Correct 36 ms 47968 KB Output is correct
7 Correct 36 ms 47992 KB Output is correct
8 Correct 42 ms 47992 KB Output is correct
9 Correct 37 ms 47992 KB Output is correct
10 Correct 35 ms 47872 KB Output is correct
11 Correct 36 ms 47872 KB Output is correct
12 Correct 43 ms 47864 KB Output is correct
13 Correct 35 ms 47872 KB Output is correct
14 Correct 35 ms 47992 KB Output is correct
15 Correct 35 ms 47872 KB Output is correct
16 Correct 36 ms 47864 KB Output is correct
17 Correct 35 ms 47864 KB Output is correct
18 Correct 35 ms 47872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47488 KB Output is correct
2 Correct 33 ms 47608 KB Output is correct
3 Correct 37 ms 48000 KB Output is correct
4 Correct 37 ms 47968 KB Output is correct
5 Correct 40 ms 47992 KB Output is correct
6 Correct 36 ms 47968 KB Output is correct
7 Correct 36 ms 47992 KB Output is correct
8 Correct 42 ms 47992 KB Output is correct
9 Correct 37 ms 47992 KB Output is correct
10 Correct 35 ms 47872 KB Output is correct
11 Correct 36 ms 47872 KB Output is correct
12 Correct 43 ms 47864 KB Output is correct
13 Correct 35 ms 47872 KB Output is correct
14 Correct 35 ms 47992 KB Output is correct
15 Correct 35 ms 47872 KB Output is correct
16 Correct 36 ms 47864 KB Output is correct
17 Correct 35 ms 47864 KB Output is correct
18 Correct 35 ms 47872 KB Output is correct
19 Correct 59 ms 49648 KB Output is correct
20 Correct 68 ms 50040 KB Output is correct
21 Correct 61 ms 49944 KB Output is correct
22 Correct 62 ms 50044 KB Output is correct
23 Correct 64 ms 49844 KB Output is correct
24 Correct 60 ms 49740 KB Output is correct
25 Correct 58 ms 49656 KB Output is correct
26 Correct 62 ms 49656 KB Output is correct
27 Correct 69 ms 49692 KB Output is correct
28 Correct 60 ms 49656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 49072 KB Output is correct
2 Correct 84 ms 50808 KB Output is correct
3 Correct 125 ms 52472 KB Output is correct
4 Correct 129 ms 52472 KB Output is correct
5 Correct 130 ms 52452 KB Output is correct
6 Correct 122 ms 52472 KB Output is correct
7 Correct 129 ms 52620 KB Output is correct
8 Correct 126 ms 52528 KB Output is correct
9 Correct 136 ms 52472 KB Output is correct
10 Correct 107 ms 52600 KB Output is correct
11 Correct 104 ms 52604 KB Output is correct
12 Correct 108 ms 52856 KB Output is correct
13 Correct 102 ms 52600 KB Output is correct
14 Correct 114 ms 52600 KB Output is correct
15 Correct 101 ms 52616 KB Output is correct
16 Correct 98 ms 52600 KB Output is correct
17 Correct 101 ms 52600 KB Output is correct
18 Correct 97 ms 52600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47488 KB Output is correct
2 Correct 33 ms 47608 KB Output is correct
3 Correct 37 ms 48000 KB Output is correct
4 Correct 37 ms 47968 KB Output is correct
5 Correct 40 ms 47992 KB Output is correct
6 Correct 36 ms 47968 KB Output is correct
7 Correct 36 ms 47992 KB Output is correct
8 Correct 42 ms 47992 KB Output is correct
9 Correct 37 ms 47992 KB Output is correct
10 Correct 35 ms 47872 KB Output is correct
11 Correct 36 ms 47872 KB Output is correct
12 Correct 43 ms 47864 KB Output is correct
13 Correct 35 ms 47872 KB Output is correct
14 Correct 35 ms 47992 KB Output is correct
15 Correct 35 ms 47872 KB Output is correct
16 Correct 36 ms 47864 KB Output is correct
17 Correct 35 ms 47864 KB Output is correct
18 Correct 35 ms 47872 KB Output is correct
19 Correct 59 ms 49648 KB Output is correct
20 Correct 68 ms 50040 KB Output is correct
21 Correct 61 ms 49944 KB Output is correct
22 Correct 62 ms 50044 KB Output is correct
23 Correct 64 ms 49844 KB Output is correct
24 Correct 60 ms 49740 KB Output is correct
25 Correct 58 ms 49656 KB Output is correct
26 Correct 62 ms 49656 KB Output is correct
27 Correct 69 ms 49692 KB Output is correct
28 Correct 60 ms 49656 KB Output is correct
29 Correct 58 ms 49072 KB Output is correct
30 Correct 84 ms 50808 KB Output is correct
31 Correct 125 ms 52472 KB Output is correct
32 Correct 129 ms 52472 KB Output is correct
33 Correct 130 ms 52452 KB Output is correct
34 Correct 122 ms 52472 KB Output is correct
35 Correct 129 ms 52620 KB Output is correct
36 Correct 126 ms 52528 KB Output is correct
37 Correct 136 ms 52472 KB Output is correct
38 Correct 107 ms 52600 KB Output is correct
39 Correct 104 ms 52604 KB Output is correct
40 Correct 108 ms 52856 KB Output is correct
41 Correct 102 ms 52600 KB Output is correct
42 Correct 114 ms 52600 KB Output is correct
43 Correct 101 ms 52616 KB Output is correct
44 Correct 98 ms 52600 KB Output is correct
45 Correct 101 ms 52600 KB Output is correct
46 Correct 97 ms 52600 KB Output is correct
47 Correct 1315 ms 101228 KB Output is correct
48 Correct 5080 ms 201744 KB Output is correct
49 Correct 5797 ms 215624 KB Output is correct
50 Correct 5799 ms 215684 KB Output is correct
51 Correct 5799 ms 215928 KB Output is correct
52 Correct 7125 ms 215756 KB Output is correct
53 Correct 6277 ms 215724 KB Output is correct
54 Correct 5476 ms 215756 KB Output is correct
55 Correct 6309 ms 215672 KB Output is correct
56 Correct 5289 ms 215796 KB Output is correct
57 Correct 5413 ms 215660 KB Output is correct
58 Correct 5133 ms 215656 KB Output is correct
59 Correct 4509 ms 203036 KB Output is correct
60 Correct 4451 ms 202704 KB Output is correct
61 Correct 4570 ms 202860 KB Output is correct
62 Correct 4398 ms 196876 KB Output is correct
63 Correct 4541 ms 196780 KB Output is correct
64 Correct 4471 ms 196768 KB Output is correct
65 Correct 4247 ms 190884 KB Output is correct
66 Correct 4248 ms 190656 KB Output is correct
67 Correct 4281 ms 190696 KB Output is correct