QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#623825 | #7617. Spectacle | ucup-team4992# | WA | 1ms | 4640kb | C++20 | 1.6kb | 2024-10-09 14:07:21 | 2024-10-09 14:07:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct DSU{
vector<int>fa,sz;
DSU(int siz):fa(siz+1),sz(siz+1){
for(int i=1;i<=siz;i++){
fa[i]=i;
}
}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void merge(int x,int y){
x=find(x);y=find(y);
if(x==y) return;
fa[x]=y;
sz[y]+=sz[x];
}
};
const int maxn=2e5+10;
using pii=pair<int,int>;
using Edge=tuple<int,int,int>;
int ans[maxn],a[maxn];
int n;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n;
vector<pii>edges;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=1;i<n;i++){
edges.push_back({a[i+1]-a[i],i});
}
sort(edges.begin(),edges.end());
DSU dsu(n);
memset(ans,0x3f3f3f3f,sizeof(ans));
for(int i=0,j=0;i<n-1;i++){
int oj=j;
auto [df,id]=edges[i];
dsu.sz[id]=1;
j++;
int u=id-1;
u=dsu.find(u);
if(dsu.sz[u]!=0){
u=dsu.find(u);
j-=(dsu.sz[u]+1)/2;
j-=(dsu.sz[dsu.find(id)]+1)/2;
dsu.merge(id,u);
j+=(dsu.sz[u]+1)/2;
}
u=id+1;
u=dsu.find(u);
if(dsu.sz[u]!=0){
u=dsu.find(u);
j-=(dsu.sz[u]+1)/2;
j-=(dsu.sz[dsu.find(id)]+1)/2;
dsu.merge(id,u);
j+=(dsu.sz[u]+1)/2;
}
for(int k=oj+1;k<=j;k++){
ans[k]=min(ans[k],df);
}
}
for(int i=1;i<=(n/2);i++){
cout<<ans[i]<<' ';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4640kb
input:
6 100 13 20 14 10 105
output:
1 5 6
result:
ok single line: '1 5 6 '
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4408kb
input:
2 1 1000000000000000000
output:
1061109567
result:
wrong answer 1st lines differ - expected: '999999999999999999', found: '1061109567 '