QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#583684 | #6414. Classical Maximization Problem | huaxiamengjin# | WA | 164ms | 30280kb | C++14 | 1.7kb | 2024-09-22 21:12:25 | 2024-09-22 21:12:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,tot;
int ct[400100],ct2[400100];
vector<int>g1[400100],g2[400100];
int a[400200];
int x[400100],y[400100];
vector<int>s;
priority_queue<pair<int,int>>q;
int used[400100];
void del(int i){
ct[x[i]]--,ct2[y[i]]--;
for (auto j:g1[x[i]])
q.push({-(ct[x[j]]+ct2[y[j]]),j});
for (auto j:g2[y[i]])
q.push({-(ct[x[j]]+ct2[y[j]]),j});
}
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++)
g1[i].clear(),g2[i].clear(),ct[i]=ct2[i]=0;
s.clear();
while(q.size())q.pop();
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;
for (int i=1;i<=n;i++)
g1[x[i]].push_back(i),g2[y[i]].push_back(i),
s.push_back(i),ct[x[i]]++,ct2[y[i]]++;
for (int i=1;i<=n;i++)
q.push({-(ct[x[i]]+ct[y[i]]),i});
int zong=0;
vector<pair<int,int> >ans;
while(q.size()){
int i=q.top().second;q.pop();
if(used[i]==1)continue;
bool fl=1;used[i]=1;del(i);
while(g1[x[i]].size()&&used[g1[x[i]].back()]==1)g1[x[i]].pop_back();
if(g1[x[i]].size()){ans.push_back({i,g1[x[i]].back()}),zong++;used[g1[x[i]].back()]=1;del(g1[x[i]].back());continue;}
while(g2[y[i]].size()&&used[g2[y[i]].back()]==1)g2[y[i]].pop_back();
if(g2[y[i]].size()){ans.push_back({i,g2[y[i]].back()}),zong++;used[g2[y[i]].back()]=1;del(g2[y[i]].back());continue;}
while(used[s.back()]==1)s.pop_back();
ans.push_back({i,s.back()});used[s.back()]=1;del(s.back());
}
cout<<zong<<"\n";
for (auto i:ans)cout<<i.first<<" "<<i.second<<"\n";
}
int main(){
int T;cin>>T;
while(T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 30280kb
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 4 3 2 1 2 4 3 2 1 0 4 3 2 1
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 164ms
memory: 30248kb
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 4 3 2 1 0 6 5 4 3 2 1 0 2 1 0 12 11 10 9 8 7 6 5 4 3 2 1 0 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 2 1 0 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 6 5 4 3...
result:
ok ok (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 160ms
memory: 30256kb
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 2 1 0 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 28 27 26 25 2...
result:
wrong answer worse than author's solution: expected 1, found 0 (test case 2517)