QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#352481 | #7993. 哈密顿 | lexiyvv | RE | 0ms | 3628kb | C++14 | 1.6kb | 2024-03-13 11:29:03 | 2024-03-13 11:29:04 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a[100005],b[100005],ans;
set<pair<int,pair<int,int> > >s00,s01,s10,s11;
void ins(int x,int y){
// cout<<"ins"<<x<<' '<<y<<endl;
ans+=abs(a[x]-b[y]);
s00.insert({-a[x]-b[y]-abs(a[x]-b[y]),{x,y}});
s01.insert({-a[x]+b[y]-abs(a[x]-b[y]),{x,y}});
s10.insert({a[x]-b[y]-abs(a[x]-b[y]),{x,y}});
s11.insert({a[x]+b[y]-abs(a[x]-b[y]),{x,y}});
}
void del(int x,int y){
// cout<<"del"<<x<<' '<<y<<endl;
ans-=abs(a[x]-b[y]);
s00.erase(s00.find({-a[x]-b[y]-abs(a[x]-b[y]),{x,y}}));
s01.erase(s01.find({-a[x]+b[y]-abs(a[x]-b[y]),{x,y}}));
s10.erase(s10.find({a[x]-b[y]-abs(a[x]-b[y]),{x,y}}));
s11.erase(s11.find({a[x]+b[y]-abs(a[x]-b[y]),{x,y}}));
}
signed main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i];
ins(1,1);
for(int i=2;i<=n;i++){
int m00=(*s00.rbegin()).first+a[i]+b[i];pair<int,int>p00=(*s00.rbegin()).second;
int m01=(*s01.rbegin()).first-a[i]+b[i];pair<int,int>p01=(*s01.rbegin()).second;
int m10=(*s10.rbegin()).first+a[i]-b[i];pair<int,int>p10=(*s10.rbegin()).second;
int m11=(*s11.rbegin()).first+a[i]-b[i];pair<int,int>p11=(*s11.rbegin()).second;
int mx=max(max(m00,m01),max(m10,m11));
if(m00==mx){
del(p00.first,p00.second);
ins(p00.first,i);ins(i,p00.second);
}
else if(m01==mx){
del(p01.first,p01.second);
ins(p01.first,i);ins(i,p01.second);
}
else if(m10==mx){
del(p10.first,p10.second);
ins(p10.first,i);ins(i,p10.second);
}
else if(m11==mx){
del(p11.first,p01.second);
ins(p11.first,i);ins(i,p11.second);
}
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
3 1 10 8 2 4 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
2 732734236 669531729 368612323 916696032
output:
484881202
result:
ok single line: '484881202'
Test #3:
score: -100
Runtime Error
input:
96739 960257511 790393830 766983782 374475134 476482176 529858300 310917487 76906076 81191659 653180897 119832756 362638666 228783015 626981197 74837554 781854003 663345706 153150021 576244413 708232220 842559077 417230462 249522463 815253339 391663517 742521049 60507117 258429449 112143256 81408991...