QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#560750 | #6409. Classical Data Structure Problem | lcqlily | WA | 0ms | 11996kb | C++14 | 2.0kb | 2024-09-12 17:41:00 | 2024-09-12 17:41:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
struct A{int y,i,nxt;}e[800010];
int n,m1,m2,ans;
int a[200010][2];
int lk[400010],ltp;
int b[200010],c[200010];
int vis[400010],t[400010];
int d[400010];
vector<int> lft,ans1,ans2;
int dfs(int u){
vector<int> qwq;vis[u]=1;
for(int i=lk[u];i;i=e[i].nxt){
int v=e[i].y;
if(t[e[i].i]||(vis[v]&&d[v]<d[u])) continue;t[e[i].i]=1;
if(vis[v]){qwq.push_back(e[i].i);continue;}
d[v]=d[u]+1;int kk=dfs(v);
if(!kk) qwq.push_back(e[i].i);
else{
ans++;
ans1.push_back(kk);
ans2.push_back(e[i].i);
}
}
int sz=qwq.size();
for(int i=0;i+1<sz;i+=2){
ans++;
ans1.push_back(qwq[i]);
ans2.push_back(qwq[i+1]);
}
if(sz%2==0) return 0;
return qwq[sz-1];
}
int find1(int x){
int l=1,r=m1;
while(l<r){
int mid=(l+r)>>1;
if(b[mid]>=x) r=mid;
else l=mid+1;
}return l;
}
int find2(int x){
int l=1,r=m2;
while(l<r){
int mid=(l+r)>>1;
if(c[mid]>=x) r=mid;
else l=mid+1;
}return l;
}
void add(int u,int v,int i){
++ltp,e[ltp].y=v,e[ltp].i=i,e[ltp].nxt=lk[u],lk[u]=ltp;
++ltp,e[ltp].y=u,e[ltp].i=i,e[ltp].nxt=lk[v],lk[v]=ltp;
}
int main(){
//ios::sync_with_stdio(0);cin.tie(0);
int T;cin>>T;
while(T--){
cin>>n;n*=2;ltp=0;ans=0;
lft.clear();ans1.clear();ans2.clear();
for(int i=1;i<=n;i++) cin>>a[i][0]>>a[i][1];
for(int i=1;i<=n;i++) b[i]=a[i][0],c[i]=a[i][1];
sort(b+1,b+n+1);sort(c+1,c+n+1);
m1=unique(b+1,b+n+1)-b-1;
m2=unique(c+1,c+n+1)-c-1;
for(int i=1;i<=m1+m2;i++) lk[i]=vis[i]=t[i]=d[i]=0;
for(int i=1;i<=n;i++){
add(find1(a[i][0]),find2(a[i][1])+m1,i);
}
for(int i=1;i<=m1+m2;i++){
if(!vis[i]){
int kk=dfs(i);
if(kk) lft.push_back(kk);
}
}
for(int i=0;i<lft.size();i+=2){
ans1.push_back(lft[i]);
ans2.push_back(lft[i+1]);
}
cout<<ans<<"\n";
for(int i=0;i<ans1.size();i++)
cout<<ans1[i]<<" "<<ans2[i]<<"\n";
if(ans1.size()!=n/2) cout<<(100/0)<<"\n";
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11996kb
input:
5 2 2 1 1 3 3 2 1 0 0 2
output:
1 4 2 1 3 0 1 4 2 1 3 3 2 4 8 7 6 5 1 3 7 2 4 16 15 14 13 12 11 10 9 8 7 6 5 1 3
result:
wrong answer 1st numbers differ - expected: '87', found: '1'