QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#423033 | #8348. 赌徒 | Diu | 100 ✓ | 158ms | 31224kb | C++14 | 1.1kb | 2024-05-27 20:52:16 | 2024-05-27 20:52:17 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+10;
int n;
ll s[N],f[N];
struct node{
int x,v;
bool operator<(const node h)const{if(x^h.x)return x<h.x;}
}a[N];
ll X(int x){return a[x].x;}
ll Y(int x){return f[x];}
int q[N],h,t;
bool check(int i,int j,int k){
__int128 x=(Y(i)-Y(j))*(X(j)-X(k));
__int128 y=(Y(j)-Y(k))*(X(i)-X(j));
return x<y;
}
signed main(){
// freopen("data3.in","r",stdin);
scanf("%d",&n),n<<=1;
for(int i=1;i<=n;i+=2){
scanf("%d%d%d",&a[i].x,&a[i+1].x,&a[i].v),a[i+1].v=a[i].v;
}
a[0].x=1;
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i].v;
for(int i=0;i<=n;i++)f[i]=s[i]+s[i]-s[n];
ll ans=-2ll*s[n]-4;
if(n<=4000){
for(int i=0;i<=n;i++){
for(int j=0;j<=i;j++)ans=max(ans,f[i]+f[j]-4ll*a[i].x*a[j].x);
}
}else{
q[h=t=1]=0;
for(int i=1;i<=n;i++){
while(h<t&&(Y(q[t])-Y(q[t-1]))<4ll*X(i)*(X(q[t])-X(q[t-1])))--t;
if(h<=t&&X(q[t])==X(i))--t;
ans=max(ans,f[i]+f[q[t]]-4ll*a[i].x*a[q[t]].x);
if(h>=t||check(i,q[t],q[t-1]))q[++t]=i;
ans=max(ans,f[i]+f[i]-4ll*a[i].x*a[i].x);
}
}
printf("%lld\n",ans);
}
詳細信息
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 1ms
memory: 7948kb
input:
100 651038477 189263729 953550806 440398864 762467402 45848303 467602579 42839722 258136833 955656013 340436834 985138623 962742165 525866620 117803361 319733126 58825090 445655965 50230277 959415469 801214421 925191559 678215060 485878995 102080431 748846405 626417068 127754511 680829125 530743446 ...
output:
-3984667488
result:
ok single line: '-3984667488'
Test #2:
score: 0
Accepted
time: 1ms
memory: 8004kb
input:
100 1 1 100 2 2 99 3 3 98 4 4 97 5 5 96 6 6 95 7 7 94 8 8 93 9 9 92 10 10 91 11 11 90 12 12 89 13 13 88 14 14 87 15 15 86 16 16 85 17 17 84 18 18 83 19 19 82 20 20 81 21 21 80 22 22 79 23 23 78 24 24 77 25 25 76 26 26 75 27 27 74 28 28 73 29 29 72 30 30 71 31 31 70 32 32 69 33 33 68 34 34 67 35 35 6...
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7988kb
input:
100 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 100...
output:
399999000000
result:
ok single line: '399999000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7912kb
input:
100 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000...
output:
-4000000
result:
ok single line: '-4000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 8008kb
input:
100 1 2 1 3 4 1 5 6 1 7 8 1 9 10 1 11 12 1 13 14 1 15 16 1 17 18 1 19 20 1 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 27 1000000000 27 2...
output:
319999997084
result:
ok single line: '319999997084'
Subtask #2:
score: 21
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 21
Accepted
time: 3ms
memory: 7936kb
input:
1000 556753360 794327018 150116472 212403895 885211063 908402611 776190453 982300031 837010658 43115997 709411772 123047318 114175953 16115870 225778499 505972853 382021643 67378895 689971007 741742710 41589399 597258351 143289901 299212635 68182659 93630752 594259146 196764360 331501409 110463656 7...
output:
-3997854012
result:
ok single line: '-3997854012'
Test #7:
score: 0
Accepted
time: 0ms
memory: 8064kb
input:
1000 1 1 1000 2 2 999 3 3 998 4 4 997 5 5 996 6 6 995 7 7 994 8 8 993 9 9 992 10 10 991 11 11 990 12 12 989 13 13 988 14 14 987 15 15 986 16 16 985 17 17 984 18 18 983 19 19 982 20 20 981 21 21 980 22 22 979 23 23 978 24 24 977 25 25 976 26 26 975 27 27 974 28 28 973 29 29 972 30 30 971 31 31 970 32...
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 3ms
memory: 8016kb
input:
1000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 1000000000 500 500 10...
output:
3999999000000
result:
ok single line: '3999999000000'
Test #9:
score: 0
Accepted
time: 3ms
memory: 7940kb
input:
1000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 100000000...
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 3ms
memory: 7936kb
input:
1000 1 2 1 3 4 1 5 6 1 7 8 1 9 10 1 11 12 1 13 14 1 15 16 1 17 18 1 19 20 1 21 22 1 23 24 1 25 26 1 27 28 1 29 30 1 31 32 1 33 34 1 35 36 1 37 38 1 39 40 1 41 42 1 43 44 1 45 46 1 47 48 1 49 50 1 51 52 1 53 54 1 55 56 1 57 58 1 59 60 1 67 67 1000000000 67 67 1000000000 67 67 1000000000 67 67 1000000...
output:
3759999982044
result:
ok single line: '3759999982044'
Subtask #3:
score: 34
Accepted
Test #11:
score: 34
Accepted
time: 158ms
memory: 29360kb
input:
500000 243340130 869967634 721560056 79570239 750056031 966348473 404026098 300201750 803030673 729195387 563457224 59818849 904561712 355648412 30197525 692632473 218602585 352775399 118124695 444872952 793854346 692934439 459706288 708143356 939055658 994920111 719104230 570228202 885607167 142801...
output:
-3999993060
result:
ok single line: '-3999993060'
Subtask #4:
score: 42
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #12:
score: 42
Accepted
time: 153ms
memory: 28132kb
input:
500000 243340130 869967634 721560056 79570239 750056031 966348473 404026098 300201750 803030673 729195387 563457224 59818849 904561712 355648412 30197525 692632473 218602585 352775399 118124695 444872952 793854346 692934439 459706288 708143356 939055658 994920111 719104230 570228202 885607167 142801...
output:
-3999993060
result:
ok single line: '-3999993060'
Test #13:
score: 0
Accepted
time: 71ms
memory: 31224kb
input:
500000 1 1 500000 2 2 499999 3 3 499998 4 4 499997 5 5 499996 6 6 499995 7 7 499994 8 8 499993 9 9 499992 10 10 499991 11 11 499990 12 12 499989 13 13 499988 14 14 499987 15 15 499986 16 16 499985 17 17 499984 18 18 499983 19 19 499982 20 20 499981 21 21 499980 22 22 499979 23 23 499978 24 24 499977...
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 80ms
memory: 27460kb
input:
500000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000 2000 2000 1000000000...
output:
1999999984000000
result:
ok single line: '1999999984000000'
Test #15:
score: 0
Accepted
time: 97ms
memory: 29092kb
input:
500000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000000 1000000 1000000 1000000...
output:
1996000000000000
result:
ok single line: '1996000000000000'
Test #16:
score: 0
Accepted
time: 71ms
memory: 28748kb
input:
500000 1 2 1 3 4 1 5 6 1 7 8 1 9 10 1 11 12 1 13 14 1 15 16 1 17 18 1 19 20 1 21 22 1 23 24 1 25 26 1 27 28 1 29 30 1 31 32 1 33 34 1 35 36 1 37 38 1 39 40 1 41 42 1 43 44 1 45 46 1 47 48 1 49 50 1 51 52 1 53 54 1 55 56 1 57 58 1 59 60 1 61 62 1 63 64 1 65 66 1 67 68 1 69 70 1 71 72 1 73 74 1 75 76 ...
output:
1999199999828604
result:
ok single line: '1999199999828604'