Submission #202015

# Submission time Handle Problem Language Result Execution time Memory
202015 2020-02-13T04:42:25 Z Segtree Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
1325 ms 1144 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include"bubblesort2.h"
using namespace std;
typedef int ll;
typedef vector<ll> vll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 16010

ll solve(vll a){
    //for(auto t:a)cout<<t<<" "; cout<<"solve"<<endl;
    ll n=a.size();
    vector<ll> ids;
    ll bef=1e9;
    for(int i=n-1;i>=0;i--){
	if(bef>a[i]){
	    ids.push_back(i);
	    bef=a[i];
	}
    }
    reverse(ids.begin(),ids.end());
    ll cnt[N];
    rep(i,N)cnt[i]=0;
    for(auto t:a)cnt[t]++;
    for(auto i:ids)cnt[a[i]]--;
    ll ans=0,res=0;
    for(int i=0;i<ids[0];i++)res+=(a[i]>a[ids[0]]);
    ans=res;
    for(int i=1;i<ids.size();i++){
	res+=ids[i]-ids[i-1]-1;
	for(int j=a[ids[i-1]]+1;j<=a[ids[i]];j++){
	    res-=cnt[j];
	}
	//cout<<ids[i]<<":"<<res<<endl;
	chmax(ans,res);
    }
    return ans;
}
vll countScans(vll a,vll x,vll v){
    ll n=a.size(),q=x.size();
    if(n>8000)return a;
    vll zs;
    for(auto t:a)zs.push_back(t);
    for(auto t:v)zs.push_back(t);
    sort(all(zs));
    zs.erase(unique(all(zs)),zs.end());
    for(int i=0;i<a.size();i++)a[i]=lower_bound(all(zs),a[i])-zs.begin();
    for(int i=0;i<v.size();i++)v[i]=lower_bound(all(zs),v[i])-zs.begin();
    vll fans;
    rep(k,q){
	a[x[k]]=v[k];
	fans.push_back(solve(a));
    }
    return fans;
}
/*int main(){
    ll n,q;
    cin>>n>>q;
    vll a(n),x(q),v(q);
    rep(i,n)cin>>a[i];
    rep(i,q)cin>>x[i]>>v[i];
    vll res=countScans(a,x,v);
    for(auto t:res)cout<<t<<endl;
}
*/

Compilation message

bubblesort2.cpp: In function 'll solve(vll)':
bubblesort2.cpp:39:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<ids.size();i++){
                 ~^~~~~~~~~~~
bubblesort2.cpp: In function 'vll countScans(vll, vll, vll)':
bubblesort2.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a.size();i++)a[i]=lower_bound(all(zs),a[i])-zs.begin();
                 ~^~~~~~~~~
bubblesort2.cpp:58:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++)v[i]=lower_bound(all(zs),v[i])-zs.begin();
                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 376 KB Output is correct
2 Correct 18 ms 376 KB Output is correct
3 Correct 51 ms 504 KB Output is correct
4 Correct 54 ms 504 KB Output is correct
5 Correct 61 ms 504 KB Output is correct
6 Correct 90 ms 632 KB Output is correct
7 Correct 87 ms 508 KB Output is correct
8 Correct 79 ms 632 KB Output is correct
9 Correct 59 ms 504 KB Output is correct
10 Correct 70 ms 632 KB Output is correct
11 Correct 68 ms 504 KB Output is correct
12 Correct 68 ms 504 KB Output is correct
13 Correct 71 ms 504 KB Output is correct
14 Correct 68 ms 504 KB Output is correct
15 Correct 70 ms 504 KB Output is correct
16 Correct 68 ms 504 KB Output is correct
17 Correct 69 ms 504 KB Output is correct
18 Correct 69 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 376 KB Output is correct
2 Correct 18 ms 376 KB Output is correct
3 Correct 51 ms 504 KB Output is correct
4 Correct 54 ms 504 KB Output is correct
5 Correct 61 ms 504 KB Output is correct
6 Correct 90 ms 632 KB Output is correct
7 Correct 87 ms 508 KB Output is correct
8 Correct 79 ms 632 KB Output is correct
9 Correct 59 ms 504 KB Output is correct
10 Correct 70 ms 632 KB Output is correct
11 Correct 68 ms 504 KB Output is correct
12 Correct 68 ms 504 KB Output is correct
13 Correct 71 ms 504 KB Output is correct
14 Correct 68 ms 504 KB Output is correct
15 Correct 70 ms 504 KB Output is correct
16 Correct 68 ms 504 KB Output is correct
17 Correct 69 ms 504 KB Output is correct
18 Correct 69 ms 504 KB Output is correct
19 Correct 423 ms 868 KB Output is correct
20 Correct 506 ms 888 KB Output is correct
21 Correct 1325 ms 1144 KB Output is correct
22 Correct 765 ms 888 KB Output is correct
23 Correct 814 ms 1016 KB Output is correct
24 Correct 831 ms 888 KB Output is correct
25 Correct 815 ms 1016 KB Output is correct
26 Correct 809 ms 888 KB Output is correct
27 Correct 820 ms 904 KB Output is correct
28 Correct 831 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 376 KB Output is correct
2 Correct 18 ms 376 KB Output is correct
3 Correct 51 ms 504 KB Output is correct
4 Correct 54 ms 504 KB Output is correct
5 Correct 61 ms 504 KB Output is correct
6 Correct 90 ms 632 KB Output is correct
7 Correct 87 ms 508 KB Output is correct
8 Correct 79 ms 632 KB Output is correct
9 Correct 59 ms 504 KB Output is correct
10 Correct 70 ms 632 KB Output is correct
11 Correct 68 ms 504 KB Output is correct
12 Correct 68 ms 504 KB Output is correct
13 Correct 71 ms 504 KB Output is correct
14 Correct 68 ms 504 KB Output is correct
15 Correct 70 ms 504 KB Output is correct
16 Correct 68 ms 504 KB Output is correct
17 Correct 69 ms 504 KB Output is correct
18 Correct 69 ms 504 KB Output is correct
19 Correct 423 ms 868 KB Output is correct
20 Correct 506 ms 888 KB Output is correct
21 Correct 1325 ms 1144 KB Output is correct
22 Correct 765 ms 888 KB Output is correct
23 Correct 814 ms 1016 KB Output is correct
24 Correct 831 ms 888 KB Output is correct
25 Correct 815 ms 1016 KB Output is correct
26 Correct 809 ms 888 KB Output is correct
27 Correct 820 ms 904 KB Output is correct
28 Correct 831 ms 1144 KB Output is correct
29 Incorrect 12 ms 632 KB Output isn't correct
30 Halted 0 ms 0 KB -