QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#412024 | #8348. 赌徒 | zhouhuanyi | 100 ✓ | 266ms | 21364kb | C++14 | 1.3kb | 2024-05-15 23:16:01 | 2024-05-15 23:16:02 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 2000000
using namespace std;
const long long inf=(long long)(1e18);
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int n,top,a[N+1],b[N+1],X[N+1],dque[N+1],tong[N+1],length;
long long s[N+1],res,ans=-inf;
bool check(int x,int y,int z)
{
return (__int128)(s[y]-s[x])*(tong[z]-tong[x])<=(__int128)(s[z]-s[x])*(tong[y]-tong[x]);
}
long long F(int x,int y)
{
return s[x]+s[y]-4ll*tong[x]*tong[y]-res;
}
int main()
{
int ps;
n=read(),tong[++length]=1;
for (int i=1;i<=n;++i) a[i]=read(),b[i]=read(),X[i]=read(),tong[++length]=a[i],tong[++length]=b[i],res+=4ll*X[i];
sort(tong+1,tong+length+1),length=unique(tong+1,tong+length+1)-tong-1;
for (int i=1;i<=n;++i) s[lower_bound(tong+1,tong+length+1,a[i])-tong]+=(X[i]<<1),s[lower_bound(tong+1,tong+length+1,b[i])-tong]+=(X[i]<<1);
for (int i=1;i<=length;++i) s[i]+=s[i-1];
for (int i=1;i<=length;++i)
{
while (top>=2&&check(dque[top-1],dque[top],i)) top--;
dque[++top]=i;
}
ps=top;
for (int i=1;i<=top;++i)
{
while (ps-1>=1&&F(dque[ps-1],dque[i])>F(dque[ps],dque[i])) ps--;
ans=max(ans,F(dque[ps],dque[i]));
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 0ms
memory: 3744kb
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: 3
Accepted
time: 0ms
memory: 3784kb
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: 3
Accepted
time: 0ms
memory: 3848kb
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: 3
Accepted
time: 0ms
memory: 3744kb
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: 3
Accepted
time: 0ms
memory: 3788kb
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: 1ms
memory: 3748kb
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: 21
Accepted
time: 1ms
memory: 3816kb
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: 21
Accepted
time: 1ms
memory: 3736kb
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: 21
Accepted
time: 1ms
memory: 3764kb
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: 21
Accepted
time: 1ms
memory: 3808kb
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: 266ms
memory: 21260kb
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: 266ms
memory: 21364kb
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: 42
Accepted
time: 73ms
memory: 19452kb
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: 42
Accepted
time: 28ms
memory: 13524kb
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: 42
Accepted
time: 38ms
memory: 13560kb
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: 42
Accepted
time: 48ms
memory: 13596kb
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'