QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563678 | #8348. 赌徒 | bear0131# | 100 ✓ | 181ms | 29376kb | C++14 | 1.5kb | 2024-09-14 15:03:00 | 2024-09-14 15:03:01 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
template<typename T> inline void chmax(T &_a, const T &_b){ (_b>_a) ? (_a=_b) : (_a); }
template<typename T> inline void chmin(T &_a, const T &_b){ (_b<_a) ? (_a=_b) : (_a); }
int n, a[500500], b[500500]; ll x[500500];
pair<int, ll> p[1000100]; int cp = 0;
bool win(int i, int j, int k){
return (__int128)(p[j].first - p[i].first) * (p[k].second - p[i].second) - (__int128)(p[k].first - p[i].first) * (p[j].second - p[i].second) <= 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
ll sum = 0, ans = -INF;
p[cp++] = make_pair(1, 0);
rep(i, n) cin >> a[i] >> b[i] >> x[i], sum -= 4 * x[i], x[i] *= 2, p[cp++] = make_pair(a[i], x[i]), p[cp++] = make_pair(b[i], x[i]);
sort(p, p + cp);
for(int i = 1; i < cp; ++i) p[i].second += p[i - 1].second;
static int h[1000100], ch = 0;
rep(i, cp){
if(i < cp - 1 && p[i].first == p[i + 1].first) continue;
while(ch >= 2 && win(i, h[ch - 1], h[ch - 2])) --ch;
h[ch++] = i;
}
rep(i, cp){
while(ch >= 2 && p[h[ch - 2]].second - 4ll * p[h[ch - 2]].first * p[i].first >= p[h[ch - 1]].second - 4ll * p[h[ch - 1]].first * p[i].first) --ch;
chmax(ans, p[i].second + p[h[ch - 1]].second - 4ll * p[h[ch - 1]].first * p[i].first);
}
cout << sum + ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 2ms
memory: 11916kb
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: 1ms
memory: 11780kb
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: 11844kb
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: 1ms
memory: 11788kb
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: 1ms
memory: 11784kb
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: 2ms
memory: 11876kb
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: 9744kb
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: 0ms
memory: 11812kb
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: 0ms
memory: 11936kb
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: 11896kb
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: 165ms
memory: 27780kb
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: 181ms
memory: 28348kb
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: 87ms
memory: 29376kb
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: 85ms
memory: 27188kb
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: 99ms
memory: 28688kb
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: 79ms
memory: 27100kb
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'