QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#583462 | #6414. Classical Maximization Problem | huaxiamengjin# | WA | 171ms | 20236kb | C++14 | 1.9kb | 2024-09-22 20:01:56 | 2024-09-22 20:01:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,tot;
int ct[400100],ct2[400100];
vector<int>g[400100];
int a[400200];
int x[400100],y[400100];
vector<int>s;
int used[400100];
void solve(){
cin>>n;tot=0;n*=2;
for (int i=1;i<=n;i++)
cin>>x[i]>>y[i],a[++tot]=x[i],a[++tot]=y[i],used[i]=0;
sort(a+1,a+tot+1);
tot=unique(a+1,a+tot+1)-a-1;
for (int i=1;i<=tot;i++)
g[i].clear(),ct[i]=0;
vector<pair<int,int> >ans;
int zong=0;
for (int i=1;i<=n;i++)
x[i]=lower_bound(a+1,a+tot+1,x[i])-a,
y[i]=lower_bound(a+1,a+tot+1,y[i])-a,
g[x[i]].push_back(i);
for (int i=1;i<=tot;i++)
if(g[i].size()%2==0){
for (int j=0;j<g[i].size();j+=2)
ans.push_back({g[i][j],g[i][j+1]}),zong++;
}else{
int fl=-1;
for (int j=0;j<g[i].size();j++)
if(ct[y[g[i][j]]]!=0){fl=j;break;}
if(fl!=-1){
for (int j=0;j<g[i].size();j+=2){
if(j+1==g[i].size())break;
if(fl==j)ans.push_back({g[i][j+1],g[i][j+2]}),zong++;
if(fl==j+1)ans.push_back({g[i][j],g[i][j+2]}),zong++;
else ans.push_back({g[i][j],g[i][j+1]}),zong++;
if(fl==j||fl==j+1)j++;
}
int ii=ct[y[g[i][fl]]],fll=fl;
for (int j=0;j<g[ii].size();j++)
if(y[g[ii][j]]==y[g[i][fl]]){fl=j;break;}
for (int j=0;j<g[ii].size();j+=2){
if(j+1==g[ii].size())break;
if(fl==j)ans.push_back({g[ii][j+1],g[ii][j+2]}),zong++;
if(fl==j+1)ans.push_back({g[ii][j],g[ii][j+2]}),zong++;
else ans.push_back({g[ii][j],g[ii][j+1]}),zong++;
if(fl==j||fl==j+1)j++;
}
for (auto j:g[ii])ct[y[j]]=0;
ans.push_back({g[i][fll],g[ii][fl]});zong++;
}else{
for (auto j:g[i])ct[y[j]]=i;
}
}
vector<int>t;
for (int i=1;i<=tot;i++){
if(ct[i]!=0){
for (auto j:g[ct[i]])
t.push_back(j),ct[y[j]]=0;
}
}
for (int i=0;i<t.size();i+=2){
ans.push_back({t[i],t[i+1]});
if(x[t[i]]==x[t[i+1]])zong++;
}
cout<<zong<<"\n";
for (auto i:ans)
cout<<i.first<<" "<<i.second<<"\n";
}
int main(){
int T;cin>>T;
while(T--)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 19872kb
input:
3 2 0 0 0 1 1 0 1 1 2 0 0 0 1 0 2 0 3 2 0 0 1 1 2 2 3 3
output:
2 1 2 3 4 2 1 2 3 4 0 1 2 3 4
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 148ms
memory: 17956kb
input:
10000 2 -107276936 -310501829 419434212 585811870 -65754386 -491212232 381152038 897148193 3 -474045168 493506332 299114415 540203303 165808153 983551 -506936261 -694189769 766718170 -725540031 975267148 -593051087 1 -818952276 -762387923 584023914 -612401389 6 -77701228 -266484128 659434465 6322062...
output:
0 3 1 2 4 0 5 4 6 3 1 2 0 1 2 0 6 10 12 1 3 4 5 7 8 9 2 11 0 7 6 1 14 3 12 10 13 11 2 5 8 4 9 0 1 2 0 25 22 39 10 31 18 33 54 51 41 66 12 11 29 60 48 3 62 19 2 57 43 46 4 37 61 9 15 36 56 59 24 64 1 34 32 26 63 21 5 6 53 47 16 52 30 38 58 27 28 13 23 14 55 40 65 35 20 17 49 44 45 42 8 50 7 0 3 4 6 2...
result:
ok ok (10000 test cases)
Test #3:
score: 0
Accepted
time: 171ms
memory: 19152kb
input:
10000 1 999855386 999580905 999342928 999615227 21 999601032 999015398 999155628 999176944 999309856 999524434 999121011 999509537 999323572 999685730 999272272 999769606 999450559 999390758 999632027 999178534 999024993 999463838 999784856 999374197 999980525 999366771 999241260 999516879 999599548...
output:
0 1 2 0 24 1 23 15 22 39 42 2 8 35 31 32 18 21 20 30 36 34 11 10 14 7 16 25 38 29 9 4 12 3 26 33 19 5 6 28 37 41 13 27 17 40 0 3 25 16 17 28 15 24 7 27 29 6 18 21 8 1 23 26 9 10 13 30 12 2 22 5 4 20 11 19 14 0 20 22 25 9 28 23 16 24 19 17 18 14 21 4 5 13 7 1 2 15 6 12 10 8 27 26 11 3 0 3 20 11 22 15...
result:
ok ok (10000 test cases)
Test #4:
score: 0
Accepted
time: 143ms
memory: 20236kb
input:
10000 5 999984799 999981445 999958394 999984217 999994978 999981258 999955539 999938710 999936554 999963561 999907222 999907508 999938166 999941959 999910567 999986887 999901446 999961092 999994730 999963038 5 999916115 999962400 999948250 999940355 999954204 999920844 999928148 999990369 999978118 ...
output:
0 6 4 7 9 10 5 3 1 2 8 0 5 8 3 6 7 2 10 1 4 9 0 20 17 18 3 4 1 22 2 8 12 21 6 7 15 14 10 16 9 19 5 13 11 0 8 6 5 4 1 7 2 3 0 8 15 30 7 25 4 20 19 23 13 9 26 2 5 31 10 18 29 28 17 24 14 3 6 11 1 21 12 22 32 16 27 0 2 6 10 8 7 1 3 4 9 5 0 5 11 16 15 4 12 1 7 13 10 14 9 8 6 3 2 0 20 63 4 62 24 44 65 38...
result:
ok ok (10000 test cases)
Test #5:
score: 0
Accepted
time: 142ms
memory: 20188kb
input:
10000 1 999990146 999993828 999995909 999996353 56 999999851 999991179 999997250 999997987 999990590 999997316 999997350 999996856 999997034 999996236 999999396 999996897 999991180 999993309 999991265 999995185 999993952 999994054 999990210 999994471 999993201 999995893 999997170 999998971 999998201...
output:
0 1 2 1 76 111 58 85 47 69 23 87 105 57 28 31 42 1 67 88 52 34 45 101 39 97 75 71 33 77 20 50 30 112 106 102 93 53 35 104 7 95 60 59 40 70 86 9 103 27 74 46 78 10 17 56 84 89 65 51 107 8 24 13 98 11 49 25 41 5 82 62 4 18 6 22 61 83 100 72 43 3 54 32 81 91 36 44 90 21 2 79 16 96 68 99 55 110 94 73 26...
result:
ok ok (10000 test cases)
Test #6:
score: -100
Wrong Answer
time: 154ms
memory: 20004kb
input:
10000 5 999999432 999999813 999999271 999999233 999999043 999999606 999999523 999999406 999999564 999999274 999999641 999999102 999999903 999999858 999999058 999999098 999999974 999999119 999999643 999999620 5 999999370 999999738 999999181 999999907 999999163 999999783 999999393 999999086 999999661 ...
output:
0 8 6 9 2 5 4 3 10 1 7 0 7 9 4 5 8 6 10 1 3 2 0 2 6 4 5 1 3 0 10 1 9 4 7 8 3 5 6 2 1 9 10 28 21 11 25 15 4 19 6 16 13 17 24 12 20 33 30 3 7 8 34 18 1 2 26 14 27 23 31 22 5 29 32 1 12 13 4 1 15 10 11 5 16 9 8 3 6 2 7 14 0 1 4 3 2 0 1 2 3 4 1 10 44 8 2 29 36 42 39 48 41 46 31 17 16 49 43 3 30 11 9 27 ...
result:
wrong answer point 56 used twice (test case 2133)