QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#827461 | #9865. Dolls | gxy001 | RE | 1ms | 3596kb | C++23 | 1.7kb | 2024-12-22 23:29:41 | 2024-12-22 23:29:42 |
Judging History
answer
#include<iostream>
#include<iomanip>
#include<cmath>
#include<numbers>
#include<algorithm>
#include<set>
using std::cin,std::cout;
int n,a[100010],mn[100010],mx[100010],w[100010],b[100010];
int get(int x,int y){
if(std::max(mn[x],mn[y])<=std::min(mx[x],mx[y])) return 0;
if(mx[x]>mx[y]) std::swap(x,y);
return mn[y]-mx[x];
}
std::set<std::pair<int,int>> st;
std::set<int> pr;
int check(int l,int r){
for(int i=l;i<=r;i++) b[i-l]=a[i];
std::sort(b,b+r-l+1);
pr.clear(),st.clear();
for(int i=l;i<=r;i++) pr.emplace(i),mx[i]=mn[i]=std::lower_bound(b,b+r-l+1,a[i])-b+1;
for(int i=l;i<r;i++) st.emplace(w[i]=std::abs(mx[i]-mx[i+1]),i);
int ans=0;
while(st.size()){
++ans;
int x=st.begin()->second;
if(st.begin()->first!=1) return false;
st.erase(st.begin());
auto it=pr.lower_bound(x);
if(x!=1){
int u=*std::prev(it);
if(w[u]) st.erase(std::pair(w[u],u));
}
int u=*++it;
it=pr.erase(it);
if(w[u]) st.erase(std::pair(w[u],u));
mx[x]=std::max(mx[u],mx[x]);
mn[x]=std::min(mn[u],mn[x]);
if(it!=pr.end()){
int u=*it;
int v=get(u,x);
if(v) st.emplace(w[x]=v,x);
}
if(x!=1){
int u=*std::prev(--it);
int v=get(u,x);
if(v) st.emplace(w[u]=v,u);
}
}
return ans==r-l;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],mn[i]=mx[i]=a[i];
int ans=0;
for(int l=1,r;l<=n;){
int len=1;
while(l+len-1<n&&check(l,l+len-1))len*=2;
int L=l+1,R=std::min(l+len-1,n);
r=l;
while(L<=R){
int mid=(L+R)>>1;
if(check(l,mid)) L=mid+1,r=mid;
else R=mid-1;
}
l=r+1;
++ans;
}
cout<<n-ans<<'\n';
}
int T;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin>>T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
input:
8 4 2 1 4 3 4 1 4 2 3 4 3 1 4 2 5 1 3 5 2 4 5 1 4 2 5 3 5 2 5 3 1 4 6 1 3 6 5 2 4 6 2 5 1 3 6 4
output:
3 3 2 3 3 3 4 4
result:
ok 8 numbers
Test #2:
score: -100
Runtime Error
input:
5913 1 1 2 1 2 2 2 1 3 1 2 3 3 1 3 2 3 2 1 3 3 2 3 1 3 3 1 2 3 3 2 1 4 1 2 3 4 4 1 2 4 3 4 1 3 2 4 4 1 3 4 2 4 1 4 2 3 4 1 4 3 2 4 2 1 3 4 4 2 1 4 3 4 2 3 1 4 4 2 3 4 1 4 2 4 1 3 4 2 4 3 1 4 3 1 2 4 4 3 1 4 2 4 3 2 1 4 4 3 2 4 1 4 3 4 1 2 4 3 4 2 1 4 4 1 2 3 4 4 1 3 2 4 4 2 1 3 4 4 2 3 1 4 4 3 1 2 4...