Submission #412415

# Submission time Handle Problem Language Result Execution time Memory
412415 2021-05-26T20:27:33 Z nichke Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
6153 ms 215664 KB
#include<bits/stdc++.h>
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#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(int i=0;i<cnt;i++){
        id[i].insert(-maxn);
    }
    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);
    }
    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;
}

Compilation message

bubblesort2.cpp: In function 'void solve()':
bubblesort2.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
bubblesort2.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int q=0;q<pos.size();q++){
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47432 KB Output is correct
2 Correct 32 ms 47508 KB Output is correct
3 Correct 41 ms 47796 KB Output is correct
4 Correct 36 ms 47872 KB Output is correct
5 Correct 37 ms 47820 KB Output is correct
6 Correct 36 ms 47792 KB Output is correct
7 Correct 36 ms 47812 KB Output is correct
8 Correct 36 ms 47884 KB Output is correct
9 Correct 36 ms 47812 KB Output is correct
10 Correct 34 ms 47824 KB Output is correct
11 Correct 35 ms 47820 KB Output is correct
12 Correct 35 ms 47792 KB Output is correct
13 Correct 35 ms 47812 KB Output is correct
14 Correct 35 ms 47820 KB Output is correct
15 Correct 36 ms 47784 KB Output is correct
16 Correct 35 ms 47764 KB Output is correct
17 Correct 35 ms 47724 KB Output is correct
18 Correct 39 ms 47788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47432 KB Output is correct
2 Correct 32 ms 47508 KB Output is correct
3 Correct 41 ms 47796 KB Output is correct
4 Correct 36 ms 47872 KB Output is correct
5 Correct 37 ms 47820 KB Output is correct
6 Correct 36 ms 47792 KB Output is correct
7 Correct 36 ms 47812 KB Output is correct
8 Correct 36 ms 47884 KB Output is correct
9 Correct 36 ms 47812 KB Output is correct
10 Correct 34 ms 47824 KB Output is correct
11 Correct 35 ms 47820 KB Output is correct
12 Correct 35 ms 47792 KB Output is correct
13 Correct 35 ms 47812 KB Output is correct
14 Correct 35 ms 47820 KB Output is correct
15 Correct 36 ms 47784 KB Output is correct
16 Correct 35 ms 47764 KB Output is correct
17 Correct 35 ms 47724 KB Output is correct
18 Correct 39 ms 47788 KB Output is correct
19 Correct 58 ms 49428 KB Output is correct
20 Correct 61 ms 49732 KB Output is correct
21 Correct 67 ms 49684 KB Output is correct
22 Correct 61 ms 49704 KB Output is correct
23 Correct 67 ms 49524 KB Output is correct
24 Correct 58 ms 49604 KB Output is correct
25 Correct 59 ms 49512 KB Output is correct
26 Correct 61 ms 49516 KB Output is correct
27 Correct 55 ms 49348 KB Output is correct
28 Correct 56 ms 49400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 48940 KB Output is correct
2 Correct 82 ms 50328 KB Output is correct
3 Correct 127 ms 51884 KB Output is correct
4 Correct 115 ms 51856 KB Output is correct
5 Correct 125 ms 51880 KB Output is correct
6 Correct 114 ms 51912 KB Output is correct
7 Correct 121 ms 51936 KB Output is correct
8 Correct 113 ms 51820 KB Output is correct
9 Correct 117 ms 51892 KB Output is correct
10 Correct 101 ms 51848 KB Output is correct
11 Correct 113 ms 52512 KB Output is correct
12 Correct 118 ms 52528 KB Output is correct
13 Correct 98 ms 52472 KB Output is correct
14 Correct 100 ms 52552 KB Output is correct
15 Correct 115 ms 52528 KB Output is correct
16 Correct 95 ms 52492 KB Output is correct
17 Correct 94 ms 52552 KB Output is correct
18 Correct 103 ms 52448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47432 KB Output is correct
2 Correct 32 ms 47508 KB Output is correct
3 Correct 41 ms 47796 KB Output is correct
4 Correct 36 ms 47872 KB Output is correct
5 Correct 37 ms 47820 KB Output is correct
6 Correct 36 ms 47792 KB Output is correct
7 Correct 36 ms 47812 KB Output is correct
8 Correct 36 ms 47884 KB Output is correct
9 Correct 36 ms 47812 KB Output is correct
10 Correct 34 ms 47824 KB Output is correct
11 Correct 35 ms 47820 KB Output is correct
12 Correct 35 ms 47792 KB Output is correct
13 Correct 35 ms 47812 KB Output is correct
14 Correct 35 ms 47820 KB Output is correct
15 Correct 36 ms 47784 KB Output is correct
16 Correct 35 ms 47764 KB Output is correct
17 Correct 35 ms 47724 KB Output is correct
18 Correct 39 ms 47788 KB Output is correct
19 Correct 58 ms 49428 KB Output is correct
20 Correct 61 ms 49732 KB Output is correct
21 Correct 67 ms 49684 KB Output is correct
22 Correct 61 ms 49704 KB Output is correct
23 Correct 67 ms 49524 KB Output is correct
24 Correct 58 ms 49604 KB Output is correct
25 Correct 59 ms 49512 KB Output is correct
26 Correct 61 ms 49516 KB Output is correct
27 Correct 55 ms 49348 KB Output is correct
28 Correct 56 ms 49400 KB Output is correct
29 Correct 48 ms 48940 KB Output is correct
30 Correct 82 ms 50328 KB Output is correct
31 Correct 127 ms 51884 KB Output is correct
32 Correct 115 ms 51856 KB Output is correct
33 Correct 125 ms 51880 KB Output is correct
34 Correct 114 ms 51912 KB Output is correct
35 Correct 121 ms 51936 KB Output is correct
36 Correct 113 ms 51820 KB Output is correct
37 Correct 117 ms 51892 KB Output is correct
38 Correct 101 ms 51848 KB Output is correct
39 Correct 113 ms 52512 KB Output is correct
40 Correct 118 ms 52528 KB Output is correct
41 Correct 98 ms 52472 KB Output is correct
42 Correct 100 ms 52552 KB Output is correct
43 Correct 115 ms 52528 KB Output is correct
44 Correct 95 ms 52492 KB Output is correct
45 Correct 94 ms 52552 KB Output is correct
46 Correct 103 ms 52448 KB Output is correct
47 Correct 1338 ms 100820 KB Output is correct
48 Correct 5047 ms 201792 KB Output is correct
49 Correct 5526 ms 215612 KB Output is correct
50 Correct 5524 ms 215500 KB Output is correct
51 Correct 5486 ms 215584 KB Output is correct
52 Correct 5596 ms 215440 KB Output is correct
53 Correct 6153 ms 215480 KB Output is correct
54 Correct 5187 ms 215636 KB Output is correct
55 Correct 5371 ms 215560 KB Output is correct
56 Correct 4888 ms 215664 KB Output is correct
57 Correct 5127 ms 215644 KB Output is correct
58 Correct 4812 ms 215568 KB Output is correct
59 Correct 4332 ms 202776 KB Output is correct
60 Correct 4278 ms 202796 KB Output is correct
61 Correct 4290 ms 202560 KB Output is correct
62 Correct 4054 ms 196660 KB Output is correct
63 Correct 4048 ms 196572 KB Output is correct
64 Correct 4005 ms 196616 KB Output is correct
65 Correct 3804 ms 190540 KB Output is correct
66 Correct 3797 ms 190568 KB Output is correct
67 Correct 3732 ms 190636 KB Output is correct