QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575439 | #5710. Solar Flight | zlt | 25 ✓ | 741ms | 203600kb | C++14 | 5.0kb | 2024-09-19 14:20:56 | 2024-09-19 14:21:00 |
Judging History
answer
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
bool Mst;
namespace IO {
char ibuf[1 << 20], *iS, *iT, obuf[1 << 20], *oS = obuf;
#define writesp(x) write(x), pc(' ')
#define writeln(x) write(x), pc('\n')
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, 1 << 20, stdin), (iS == iT ? EOF : *iS++) : *iS++)
template<typename T = int>
inline T read () {
char ch = gh();
T x = 0;
bool t = 0;
while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
return t ? ~(x - 1) : x;
}
inline void flush () {
fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;
}
inline void pc (char ch) {
if (oS == obuf + (1 << 20)) flush();
*oS++ = ch;
}
template<typename T>
inline void write (T x) {
static char stk[64], *tp = stk;
if (x < 0) {
x = ~(x - 1);
pc('-');
}
do {
*tp++ = x % 10;
x /= 10;
} while (x);
while (tp != stk) {
pc((*--tp) | 48);
}
}
}
using IO::read;
using IO::write;
using IO::pc;
using IO::flush;
const int maxn = 2020;
ll n, m, K, id[maxn], a[maxn], b[maxn], c[maxn], d[maxn], p[maxn], q[maxn], h[maxn];
struct frac {
ll x, y;
frac(ll a = 0, ll b = 1) {
if (b < 0) {
a = -a;
b = -b;
}
x = a;
y = b;
}
};
struct node {
frac x;
ll y, z;
} g[maxn];
frac f[maxn][maxn];
bool e[maxn][maxn];
int len[maxn];
inline bool operator < (const frac &a, const frac &b) {
return (lll)a.x * b.y < (lll)a.y * b.x;
}
inline bool operator <= (const frac &a, const frac &b) {
return (lll)a.x * b.y <= (lll)a.y * b.x;
}
inline bool operator == (const frac &a, const frac &b) {
return (lll)a.x * b.y == (lll)a.y * b.x;
}
struct SGT {
ll a[8200];
inline void pushup(int x) {
a[x] = max(a[x << 1], a[x << 1 | 1]);
}
void build(int rt, int l, int r) {
if (l == r) {
a[rt] = h[l];
return;
}
int mid = (l + r) >> 1;
build(rt << 1, l, mid);
build(rt << 1 | 1, mid + 1, r);
pushup(rt);
}
void query(int rt, int l, int r, int ql, int qr, ll &x) {
if (ql > qr) {
return;
}
if (ql <= l && r <= qr) {
x = max(x, a[rt]);
return;
}
int mid = (l + r) >> 1;
if (ql <= mid) {
query(rt << 1, l, mid, ql, qr, x);
}
if (qr > mid) {
query(rt << 1 | 1, mid + 1, r, ql, qr, x);
}
}
} T[maxn];
inline int find(frac a[maxn], bool b[maxn], int l, int r, ll x) {
int pos = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (((b[mid] && a[mid].x < x * a[mid].y) || (!b[mid] && a[mid].x <= x * a[mid].y))) {
pos = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
assert(pos != -1);
return pos;
}
void solve() {
m = read();
ll X = read();
n = read();
K = read();
map<pii, ll> mp;
map< pii, vector<int> > pm;
for (int i = 1; i <= n; ++i) {
a[i] = read();
b[i] = read();
c[i] = read();
mp[mkp(a[i], b[i])] += c[i];
pm[mkp(a[i], b[i])].pb(i);
}
n = 0;
for (auto p : mp) {
a[++n] = p.fst.fst;
b[n] = p.fst.scd;
c[n] = p.scd;
for (int i : pm[mkp(a[n], b[n])]) {
id[i] = n;
}
}
for (int i = 1; i <= n; ++i) {
p[i] = i;
}
sort(p + 1, p + n + 1, [&](const ll &x, const ll &y) {
return b[x] - a[x] < b[y] - a[y] || (b[x] - a[x] == b[y] - a[y] && a[x] > a[y]);
});
ll s = 0;
for (int i = 1; i <= n; ++i) {
d[p[i]] = s;
s += c[p[i]];
q[p[i]] = i;
}
for (int i = 1; i <= n; ++i) {
int tot = 0;
for (int j = 1; j <= n; ++j) {
if (i == j) {
continue;
}
frac k1(b[i] - a[i], m), k2(b[j] - a[j], m);
if (k1 == k2) {
continue;
}
frac x((a[j] - a[i]) * m, k1.x - k2.x);
g[++tot].x = x;
g[tot].y = (q[i] < q[j] ? c[j] : -c[j]);
g[tot].z = (q[i] < q[j]);
}
sort(g + 1, g + tot + 1, [&](const node &a, const node &b) {
return (lll)a.x.x * b.x.y < (lll)b.x.x * a.x.y || ((lll)a.x.x * b.x.y == (lll)b.x.x * a.x.y && a.z < b.z);
});
f[i][0] = frac(-4e18, 1);
e[i][0] = 0;
ll s = d[i];
h[0] = s;
for (int j = 1, k = 1; j <= tot; j = (++k)) {
while (k < tot && g[k + 1].x == g[j].x && g[k + 1].z == g[j].z) {
++k;
}
for (int x = j; x <= k; ++x) {
s += g[x].y;
}
h[++len[i]] = s;
f[i][len[i]] = g[j].x;
e[i][len[i]] = g[j].z;
}
T[i].build(1, 0, len[i]);
}
while (K--) {
ll x = read();
ll l = read();
ll r = l + X;
x = id[x];
int L = find(f[x], e[x], 0, len[x], l), R = find(f[x], e[x], 0, len[x], r);
ll ans = -1e18;
T[x].query(1, 0, len[x], L, R, ans);
writeln(ans);
}
}
bool Med;
int main() {
fprintf(stderr, "%.2lf MB\n", (&Mst - &Med) / 1048576.);
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
flush();
return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 3ms
memory: 84072kb
input:
1000 200 200 1000 657 836 23 962 796 47 497 305 25 837 161 23 220 575 33 697 109 37 401 221 43 883 211 46 727 461 26 681 209 28 413 14 49 664 986 27 431 222 47 307 121 38 638 560 45 801 149 24 878 61 36 761 356 43 839 413 32 931 573 35 218 195 46 201 697 25 951 778 21 705 905 42 861 391 23 582 718 2...
output:
6049 5822 2542 5950 1152 2947 2697 2357 1219 3428 1366 6013 6215 3869 2344 2630 2619 2303 4412 6066 6597 1631 6657 3093 3199 1315 2441 1501 6146 2171 3160 1032 2914 4234 692 5058 3177 3283 5036 1702 3169 1024 6614 1568 5133 2269 4032 877 6458 4609 6270 1564 877 3155 2783 3172 6136 4958 2563 3579 602...
result:
ok 1000 lines
Test #2:
score: 10
Accepted
time: 33ms
memory: 125064kb
input:
10000 4000 800 1000 75657 83836 780 11962 49796 629 89497 1305 816 49837 85161 195 28220 87575 587 68697 54109 882 68401 71221 247 51883 49211 198 76727 74461 213 88681 89209 368 94413 98014 967 53664 32986 885 46431 19222 982 74307 9121 350 1638 41560 377 95801 76149 593 75878 8061 102 17761 83356 ...
output:
66998 372651 71882 230931 117149 150398 355375 284731 10168 280887 314284 339928 385864 37803 408137 106909 273581 236358 396850 199550 414114 154206 241347 242637 89623 303605 301758 406078 286813 367590 279934 316532 315289 368177 294903 60588 306179 175416 178653 73606 123438 53572 263464 367797 ...
result:
ok 1000 lines
Test #3:
score: 10
Accepted
time: 291ms
memory: 201712kb
input:
100000 70000 2000 1000 75657 83836 2448100 11962 49796 1600996 89497 1305 2781211 49837 85161 1601062 28220 87575 1329028 68697 54109 2237292 68401 71221 2499307 51883 49211 1775046 76727 74461 2974020 88681 89209 2445860 94413 98014 1700919 53664 32986 2402956 46431 19222 1747481 74307 9121 1615935...
output:
2934379373 2922891391 3515422029 1450321827 1129612500 3943378704 2626723334 2565897601 3834435831 2545857081 2191434562 2238840383 3935335833 2981615579 706657489 2832999972 3381170831 2019351908 2449239345 3300400809 3012385670 3834105878 3707015903 3470161116 985251429 3822861893 596146397 918148...
result:
ok 1000 lines
Test #4:
score: 10
Accepted
time: 266ms
memory: 201592kb
input:
10000001 3000003 2000 1000 50 999947 783585127 95 999907 794505200 164 999891 680508956 229 999861 543263639 244 999849 889154272 325 999780 588428698 394 999749 596808712 460 999691 512172704 521 999670 646367223 592 999658 705991625 678 999565 664968144 767 999558 972852236 848 999494 964463766 93...
output:
1240513824931 1173388781740 824850620980 712840060845 1318911118904 39152826164 763158769681 1217277671244 576924223978 549671580423 1150059359951 66314878130 1337783770468 534664640455 1352506482924 1177552008572 905271273726 320514241628 867265875305 1235343030806 1118906688022 1093648045220 11305...
result:
ok 1000 lines
Test #5:
score: 10
Accepted
time: 247ms
memory: 202000kb
input:
1000000000 543212345 2000 1000 999951415 107406 176163935 999914991 275150 745519734 999832082 425326 314874995 999729085 466864 118662252 999611779 501976 207009093 999475536 573247 57066144 999357075 589628 279583004 999163538 761929 797445536 999152542 961710 723813350 998964573 970121 361676627 ...
output:
598278885569 569029417184 605580300205 506749535153 563357280225 604798626755 500812188917 487459532016 579382209540 580193252389 520191808123 529656730663 531516109605 569340871611 451046225257 548750961129 380475495528 546157700686 584124470461 617939989881 540985677891 518485722275 488243711191 3...
result:
ok 1000 lines
Subtask #2:
score: 15
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 15
Accepted
time: 402ms
memory: 203312kb
input:
10000 8237 2000 800000 999953445 183040 291726450 999918944 198561 315742340 999888657 307556 388256806 999742224 453277 220167020 999680287 456442 735058932 999485031 585755 219845170 999423156 749421 682373066 999295511 805286 252057572 999283248 926117 556240096 999227898 931100 227194256 9990908...
output:
831959167076 795406015785 816068363857 716514615188 878453316365 603399533311 774852117108 714870964757 662800416701 837945335561 694097954847 836911989211 701103654923 814993672842 818702728489 719195420752 857905075526 874887313166 783567764775 781575581133 679155641851 818040906766 672810224710 7...
result:
ok 800000 lines
Test #7:
score: 15
Accepted
time: 374ms
memory: 203492kb
input:
100 100 2000 800000 102587 999803692 211964024 302018 999699350 269696774 454859 999536969 252545126 625295 999475605 252126257 817992 999371604 383558872 911886 999355971 263041088 1046305 999281347 201839289 1105419 999193960 665915226 1175583 999008669 253099649 1250810 999003350 285798332 139574...
output:
701224914719 539711138039 503839796722 650386666373 760339758015 865354141842 680138025621 865354141842 623059721619 868309546791 619259806419 449430890345 701670970633 792688636022 812316643041 853886991382 495703685632 642839232290 582360981066 585210935200 688715151339 444918771387 473207692800 7...
result:
ok 800000 lines
Test #8:
score: 15
Accepted
time: 741ms
memory: 203232kb
input:
1000000000 600000000 2000 800000 57139 5037 429032336 19701 85840 665720090 59781 43361 784181624 14621 50479 557336474 19001 33423 550496615 81989 51896 457002400 94101 27949 811517740 19465 38171 833870822 28771 53365 356486418 19721 15473 426669362 99960 46401 319366394 19656 33968 714259944 6891...
output:
515977345583 645535427729 723268206802 822073255484 258545416410 420937557223 690898567006 697555559687 624974549696 843956242794 355675130489 338602366239 423713946770 638096499764 225863062061 707477083111 224920967294 835041598961 860590350816 730265342774 363217395700 467374807126 796987017224 7...
result:
ok 800000 lines
Test #9:
score: 15
Accepted
time: 659ms
memory: 202992kb
input:
1000000000 1 2000 800000 14175913 181539561 734906624 97299905 593615130 419688941 78326209 287717821 597672653 1448705 518329441 318406915 791238081 49945491 412478990 15399473 61511149 314627200 709027073 620212937 357201560 270670585 11437533 200614724 2638189 281866786 805832624 211552140 523795...
output:
306564847495 112626316417 653127857074 765822985640 664979221128 199940971618 386388275176 156688401026 319685877875 726775957362 143800827604 205442094198 562852894450 866741107543 441450734932 79369650608 556982386503 383956164566 658380690992 183794037943 475279692926 636276297303 401052463226 42...
result:
ok 800000 lines
Test #10:
score: 15
Accepted
time: 713ms
memory: 202964kb
input:
1000000000 100000000 2000 800000 132567565 652867053 901160061 257522409 966155203 908333850 379503397 382823461 920447995 242532616 406439681 992799293 619320099 58846555 983846124 218107290 61799849 942015399 229176325 251777101 909820600 345299593 401437108 901232224 27151201 150135031 962929905 ...
output:
161699167282 1267824442721 761438827285 201518968229 715433488925 1476268155151 1510539758522 307800875253 1516572005854 397511907507 798263836946 962064008217 1612171895669 1702676313082 188954505944 1238400454621 1630893154279 113242208379 1655098470243 669110888148 489152280668 1660947823334 9714...
result:
ok 800000 lines
Test #11:
score: 15
Accepted
time: 711ms
memory: 203296kb
input:
1000000000 900000000 2000 800000 53091026 115168417 236848160 644246481 18825177 106928070 662634965 588098446 101875750 594455625 134094593 140757632 271648026 314493761 103574714 15642641 578399365 57627548 231143377 20613230 244193956 791755642 13940641 470048512 84852288 336735153 61799912 43862...
output:
184197543245 167769571232 354699290502 550516242848 490893805926 344558203963 487406803264 280340390218 535637819463 457621475741 286487532902 141728735176 501013843101 602212905908 548190383370 506360538383 215412255375 220918614237 200986108732 398425625124 412942818633 524040735544 535728416031 1...
result:
ok 800000 lines
Test #12:
score: 15
Accepted
time: 468ms
memory: 202832kb
input:
10000000 8100000 2000 800000 439761 999706539 549970420 314890 999266338 871994734 794385 999279320 776135320 1077227 999097088 700228982 1553591 998695880 585503824 1785238 998458544 639066640 1805846 997906857 484090135 2517792 997582030 519528496 2878171 997272980 591208096 3082721 997108850 4000...
output:
664905095699 1186525905351 901803674886 797288965764 985767203499 1160540451074 656740047909 705564224788 1075897619449 1128304048785 705567014538 885877543997 1055894622181 1088008546313 639612765358 984743985543 682714016919 813391635727 1145758426895 999011682858 877297618445 601414334490 1136813...
result:
ok 800000 lines
Test #13:
score: 15
Accepted
time: 502ms
memory: 203600kb
input:
1000000000 900000001 2000 800000 1119353 998798168 478626700 1054723 998884165 463131986 1862785 997892712 906928968 1215301 998799755 667022778 2918041 998042044 582913600 3104601 997933508 505753080 3743553 996228850 404558950 3317433 996767718 537295483 3309141 995752100 705451931 4266526 9962900...
output:
854815216821 879038795062 898543469765 760554273558 1146542369053 846622772400 1056639546303 963671423468 937700395080 948265543782 891868075431 1165414992912 1136803421729 1194938990609 852494832202 871128308161 969566133122 608644724711 810112971582 849139826886 1142436212226 869051808735 11790188...
result:
ok 800000 lines