답안 #202013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202013 2020-02-13T04:38:05 Z Segtree Bubble Sort 2 (JOI18_bubblesort2) C++14
0 / 100
12 ms 760 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];
    for(auto t:a)cnt[t]++;
    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];
	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:37: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:55: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:56: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();
                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -