#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){
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++){
ans+=ids[i]-ids[i-1]-1;
for(int j=a[ids[i-1]]+1;j<=a[ids[i]];j++){
ans-=cnt[j];
}
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:36: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:53: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:54: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 |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |