ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212236 | #3811. T1 | drdilyor | 100 | 5610ms | 415284kb | C++11 | 2.9kb | 2024-10-13 15:42:38 | 2024-10-13 19:35:38 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
bool Mbe;
int ty[1000005],d[1000005],a[1000005],b[1000005];
int lsh[1000005];
int l;
multiset<int> ga[1000005],gb[1000005],ha[1000005],hb[1000005];
struct node{
int val=(1ll<<60);
int sa=(1ll<<60),sb=(1ll<<60),ta=(1ll<<60),tb=(1ll<<60);
//x 来自左边, y 来自右边.
//答案就是 bx+by.
//否则答案就是 ax+ay.
//维护区间内每个集合最小的 a 和 b.
//这个区间的 max(ax+ay,bx+by)
//ax-bx=by-ay
}seg[1000005*4];
void upd(int x){
seg[x].val=min(seg[x*2].val,seg[x*2+1].val);
seg[x].val=min(seg[x].val,seg[x*2].sb+seg[x*2+1].tb);
seg[x].val=min(seg[x].val,seg[x*2].ta+seg[x*2+1].sa);
seg[x].sa=min(seg[x*2].sa,seg[x*2+1].sa);
seg[x].sb=min(seg[x*2].sb,seg[x*2+1].sb);
seg[x].ta=min(seg[x*2].ta,seg[x*2+1].ta);
seg[x].tb=min(seg[x*2].tb,seg[x*2+1].tb);
}
void modify(int id,int l,int r,int x){
if(l==r){
seg[id].sa=(ga[x].empty()?(1ll<<60):*ga[x].begin());
seg[id].sb=(gb[x].empty()?(1ll<<60):*gb[x].begin());
seg[id].ta=(ha[x].empty()?(1ll<<60):*ha[x].begin());
seg[id].tb=(hb[x].empty()?(1ll<<60):*hb[x].begin());
if(seg[id].sa+seg[id].ta<2000000002)seg[id].val=seg[id].sa+seg[id].ta;
else seg[id].val=(1ll<<60);
//cout<<l<<" "<<r<<" "<<x<<" "<<seg[id].sa<<" "<<seg[id].sb<<" "<<seg[id].ta<<" "<<seg[id].tb<<"\n";
return;
}
int mid=(l+r)/2;
if(x<=mid)modify(id*2,l,mid,x);
else modify(id*2+1,mid+1,r,x);
upd(id);
}
bool Med;
signed main(){
//cout<<(&Mbe-&Med)/1048576.00<<"\n";
int t=read();
for(int i=1;i<=t;i++){
ty[i]=read(),d[i]=read(),a[i]=read(),b[i]=read();
if(!d[i])lsh[++l]=a[i]-b[i];
else lsh[++l]=b[i]-a[i];
}
sort(lsh+1,lsh+l+1);
int m=unique(lsh+1,lsh+l+1)-lsh-1;
for(int i=1;i<=t;i++){
if(ty[i]==1){
//加入
if(!d[i]){
//加入第 1 个集合
int x=lower_bound(lsh+1,lsh+m+1,a[i]-b[i])-lsh;
ga[x].insert(a[i]),gb[x].insert(b[i]);
modify(1,1,m,x);
}
else{
int x=lower_bound(lsh+1,lsh+m+1,b[i]-a[i])-lsh;
ha[x].insert(a[i]),hb[x].insert(b[i]);
modify(1,1,m,x);
}
}
else{
if(!d[i]){
int x=lower_bound(lsh+1,lsh+m+1,a[i]-b[i])-lsh;
ga[x].erase(ga[x].find(a[i]));
gb[x].erase(gb[x].find(b[i]));
modify(1,1,m,x);
}
else{
int x=lower_bound(lsh+1,lsh+m+1,b[i]-a[i])-lsh;
ha[x].erase(ha[x].find(a[i]));
hb[x].erase(hb[x].find(b[i]));
modify(1,1,m,x);
}
}
if(seg[1].val>2000000002){printf("-1\n");}
else printf("%lld\n",seg[1].val);
}
//ax+ay>=bx+by
//ax-bx>=by-ay
//维护 a-b 和 b-a.
//然后考虑 [l,r] 里要找出 max(ax+ay,bx+by)
//
return 0;
}
//look at my code
//my code is amazing
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 52ms
memory: 344976kb
input:
100 1 0 30056910 791979446 0 0 30056910 791979446 1 1 87818006 915325879 1 0 885405412 638527154 0 1...
output:
-1 -1 -1 1553853033 -1 -1 -1 1372223954 1160777349 1160777349 787718936 787718936 1160777349 -1 -1 -...
result:
ok 100 numbers
Subtask #2:
score: 10
Accepted
Test #2:
score: 10
Accepted
time: 56ms
memory: 344976kb
input:
100 1 0 888145469 920169409 1 0 452904566 455699108 1 0 9314511 72429163 0 0 452904566 455699108 1 1...
output:
-1 -1 -1 -1 560615725 560615725 560615725 560615725 560615725 738065491 738065491 1439446683 8215374...
result:
ok 100 numbers
Subtask #3:
score: 10
Accepted
Test #3:
score: 10
Accepted
time: 81ms
memory: 345044kb
input:
1000 1 0 434052041 886975755 1 0 5735137 42531708 1 0 333067530 62734547 0 0 434052041 886975755 1 1...
output:
-1 -1 -1 -1 839243210 831398858 1022941456 1158731251 462065303 462065303 -1 -1 407960422 407960422 ...
result:
ok 1000 numbers
Subtask #4:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 61ms
memory: 345044kb
input:
1000 1 1 99608765 102738517 1 0 409526489 651778959 1 1 632469167 447766999 1 1 596595729 295223176 ...
output:
-1 754517476 754517476 754517476 754517476 754517476 240180556 240180556 240180556 240180556 7545174...
result:
ok 1000 numbers
Subtask #5:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 55ms
memory: 345048kb
input:
1000 1 1 392884476 341683390 1 1 812391583 884023296 0 1 392884476 341683390 0 1 812391583 884023296...
output:
-1 -1 -1 -1 -1 -1 -1 1033130556 -1 -1 596121801 596121801 572006216 572006216 572006216 572006216 57...
result:
ok 1000 numbers
Subtask #6:
score: 10
Accepted
Test #6:
score: 10
Accepted
time: 370ms
memory: 358956kb
input:
200000 1 0 745208991 893565181 1 1 338915529 332862800 1 1 879402360 343669571 0 0 745208991 8935651...
output:
-1 1226427981 1226427981 -1 1156522405 1156522405 907552725 851482156 851482156 851482156 851482156 ...
result:
ok 200000 numbers
Subtask #7:
score: 10
Accepted
Test #7:
score: 10
Accepted
time: 465ms
memory: 358940kb
input:
200000 1 0 61288090 442363511 1 0 702180888 491607485 0 0 702180888 491607485 0 0 61288090 442363511...
output:
-1 -1 -1 -1 -1 1369535428 1182928863 1182928863 -1 568524713 568524713 568524713 568524713 548209901...
result:
ok 200000 numbers
Subtask #8:
score: 10
Accepted
Test #8:
score: 10
Accepted
time: 342ms
memory: 359080kb
input:
200000 1 0 965089945 885763418 1 0 47734550 558904612 0 0 47734550 558904612 1 0 511007140 115554736...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 770546713 770546713 1082209730 1082209730 1082209730 1082209730 108...
result:
ok 200000 numbers
Subtask #9:
score: 10
Accepted
Test #9:
score: 10
Accepted
time: 2103ms
memory: 415248kb
input:
1000000 1 1 598963903 48224788 1 0 880787238 21153517 1 0 874812562 609964051 0 1 598963903 48224788...
output:
-1 1479751141 1473776465 -1 -1 1484975949 1433383436 1331359936 1074242658 865998205 865998205 86599...
result:
ok 1000000 numbers
Subtask #10:
score: 10
Accepted
Test #10:
score: 10
Accepted
time: 2025ms
memory: 415284kb
input:
1000000 1 0 532848699 733617288 1 1 59884418 599409867 0 1 59884418 599409867 1 0 1137393 496603003 ...
output:
-1 1333027155 -1 -1 1118403184 1355417469 1355417469 1140899234 1085347521 1078478006 1085347521 672...
result:
ok 1000000 numbers