QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#749280 | #9722. Invaluable Assets | I_be_wanna | AC ✓ | 677ms | 44792kb | C++20 | 2.9kb | 2024-11-14 23:20:12 | 2024-11-14 23:20:13 |
Judging History
answer
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
for (int nCase = 1; nCase <= t; ++nCase) {
int n, c, q;
std::cin >> n >> c >> q;
int k = std::sqrt(c), k1 = k + 1;
if (c * k1 > k * k1 + c * k) k = k1;
std::vector<int> h(n);
for (int i = 0; i < n; ++i) std::cin >> h[i];
std::sort(h.begin(), h.end());
auto calc = [&](int n, int x) {
int l = n / x, t = n - l * x;
return x * c + l * l * (x - t) + (l + 1) * (l + 1) * t;
};
std::vector<int> dp(c + 1), g(k, 1);
for (int i = 1, j = 1; i <= c; ++i) {
while (calc(i, j) > calc(i, j + 1)) ++j;
dp[i] = calc(i, j);
g[i % k] = dp[i] * k - i * (k * k + c);
}
std::vector<std::vector<int>> cnt(n + 1, std::vector<int>(k));
std::vector<int64_t> pre(n + 1);
for (int i = 0; i < n; ++i) {
cnt[i + 1] = cnt[i];
++cnt[i + 1][h[i] % k];
pre[i + 1] = pre[i] + h[i];
}
std::cout << "Case #" << nCase << ":\n";
while (q--) {
int v;
std::cin >> v;
int j = std::lower_bound(h.begin(), h.end(), v - c) - h.begin();
int64_t ans = (int64_t(v) * j - pre[j]) * (k * k + c);
for (int x = 0; x < k; ++x) ans += int64_t(g[x]) * cnt[j][(v - x + k) % k];
ans /= k;
for (int i = j; i < n && h[i] < v; ++i) ans += dp[v - h[i]];
std::cout << ans << "\n";
}
}
return 0;
}
/*#include <bits/stdc++.h>&
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
for (int nCase = 1; nCase <= t; ++nCase) {
int n, c, q;
std::cin >> n >> c >> q;
int k = std::sqrt(c), k1 = k + 1;
if (c * k1 > k * k1 + c * k) k = k1;
std::vector<int> h(n);
for (int i = 0; i < n; ++i) std::cin >> h[i];
std::sort(h.begin(), h.end());
auto calc = [&](int n, int x) {
int l = n / x, t = n - l * x;
return x * c + l * l * (x - t) + (l + 1) * (l + 1) * t;
};
std::vector<int> dp(c + 1), g(k, 1);
for (int i = 1, j = 1; i <= c; ++i) {
while (calc(i, j) > calc(i, j + 1)) ++j;
dp[i] = calc(i, j);
g[i % k] = dp[i] * k - i * (k * k + c);
int64_t ans = (int64_t(v) * j - pre[j]) * (k * k + c);
for (int x = 0; x < k; ++x) ans += int64_t(g[x]) * cnt[j][(v - x + k) % k];
#include <bits/stdc++.h>*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
input:
2 3 2 3 3 0 2 1 2 3 4 3 5 0 2 3 4 1 2 3 4 5
output:
Case #1: 3 6 12 Case #2: 4 7 15 25 40
result:
ok 10 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
10 7 2 7 886853742 719874125 448575857 90400879 284020666 873946432 968796125 166935672 97276878 429715247 507351480 44632788 336984588 642585955 7 2 7 126777308 646807289 547660232 414727661 472932300 247630355 882287974 45902136 177525785 351869697 940694112 35450107 315748319 623010800 6 2 8 3281...
output:
Case #1: 229604379 20627997 1455026847 2097171114 0 898642893 3314281389 Case #2: 0 152245431 987995193 9738106995 0 771266925 3915978432 Case #3: 10320786933 3978516864 1350176583 9570057909 3784753224 115936302 12477099993 12303645585 Case #4: 1207572276 8464194956 5425832840 118812936 9412514576 ...
result:
ok 79 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
10 15 2 6 19747594 982144089 628809175 436731171 869697577 986981896 457278564 684107390 513342389 74875760 187949688 192856132 999702745 879426585 713289149 806423888 823713250 95846734 548259652 906037375 54975682 14 1 5 990066576 102528602 118806349 945448908 274460934 9827867 122335075 553744953...
output:
Case #1: 12465755604 12984436464 291210342 5865108798 15643011978 105684264 Case #2: 3529429370 16925843840 8335497594 10252711040 13593600884 Case #3: 497916550 601323142 4870687620 5687613270 0 6150558022 2755689728 Case #4: 48683016 0 5833049739 9011304006 0 Case #5: 12906315 4181421666 234752244...
result:
ok 79 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
10 13 2 14 300981012 260262133 891079138 471740297 216027870 717882999 865281324 172589829 325481403 935651672 833110201 168421637 852958793 542144743 950129779 823788594 283332700 385387208 222361782 807489738 413352825 940069746 306096850 770514720 941683548 46693042 748841869 13 2 10 816414622 53...
output:
Case #1: 5638527060 16020656457 11870764716 948087993 2605678092 330138030 11479592172 3109059198 15628315170 1236605307 10592191740 15691253448 0 10072043316 Case #2: 8856406851 8493457260 8055514794 1489600029 677144649 8005834992 3547410807 13043617974 7766776668 7381237908 Case #3: 4306059144 44...
result:
ok 112 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
10 9 1 8 317830264 852767977 856070012 270634196 485126767 604847535 81831589 655418111 614448596 435715350 152511993 20198292 339983740 305304112 637797778 364169144 139016418 10 2 15 773104804 818213025 369487076 113865045 997519107 121690226 426615618 117696172 335172199 259791850 612057644 28788...
output:
Case #1: 1273700002 141360808 0 699310342 516284878 2904135442 844422766 114369658 Case #2: 7620255966 1615488657 0 15968204436 15592397160 10520026203 7762942314 0 6031148313 3601364370 9870881259 5875687287 10603543371 2591460204 16739732757 Case #3: 3144970696 3047915992 5457834700 254307220 2147...
result:
ok 120 lines
Test #6:
score: 0
Accepted
time: 23ms
memory: 3980kb
input:
10 9805 1 8307 524275211 721274209 904959615 368545834 432909240 289424665 329061636 624827981 285000886 771886265 721745177 721430587 428468897 227857646 213911395 60149691 726660550 61567030 671481466 384470439 76130217 937435493 177173869 998861418 992494977 64570404 314829882 912507529 78472887 ...
output:
Case #1: 743209614100 3667992192374 45538535498 4803085872 635350660126 8171267211690 2110191821514 6705564860052 3368941207080 5203504245690 2575610513578 747412743122 5307423724 732226038678 1341703506452 7477531007600 639674441246 1244645350566 2043126130374 2084996138008 4246248777336 4957954860...
result:
ok 78576 lines
Test #7:
score: 0
Accepted
time: 27ms
memory: 4160kb
input:
10 9505 8 8170 398185467 244849218 677116374 985966000 315029421 479096325 319270188 612288616 913681571 641935431 884227101 249951372 22406576 638193170 249902358 422649685 357707388 170729833 460265114 991849005 532482563 199477696 222447037 596388146 892893460 627863678 820066986 615044536 686714...
output:
Case #1: 5809510820075 3532556694776 2414036619636 22849847452862 24524190384034 1626283235125 11024174086689 2941116203336 2766323095810 1272573035929 24688052283894 1293378665273 2042551667252 62597316955 186015048406 18509112058361 2618234135474 2407288506421 16840190445474 25260201533274 9091067...
result:
ok 75554 lines
Test #8:
score: 0
Accepted
time: 337ms
memory: 16324kb
input:
10 63050 693 53985 742755435 437714835 225451476 607048701 46649346 912846377 338845735 69287356 791528849 576195687 202431447 111166261 849313359 430560547 64834242 188564725 543688546 740835399 756600828 944987105 345411177 970499919 857150026 598732209 275526131 889167311 515061927 215137648 9245...
output:
Case #1: 484255927843221 183280113217366 140297236618723 1543650405882475 3534152808822 27179452765807 310155176707557 275935892845290 1260649770204358 8692745120098 794238276870411 154516776130495 19352351775250 905748923882896 1316734728044858 646333005523278 2566763191343 153765406700 45503555770...
result:
ok 664564 lines
Test #9:
score: 0
Accepted
time: 375ms
memory: 16724kb
input:
10 73852 682 77979 26203964 31878917 330359462 991103730 556136624 115360955 277219652 188692466 258294778 685435997 84419057 94463464 790615778 660577755 212538738 801535823 127536326 494432990 739107164 356728729 705756441 415452478 593027229 826344362 885217758 591749004 308082676 890156123 65138...
output:
Case #1: 550264829354443 658512195139711 705229240175886 59211375864000 53147736272871 1433777933765759 30321568079053 160601968321124 254795476085080 371125142469136 223505119189819 211715893672206 364832168716933 8245583174622 686919385311129 1770950254694054 1083693147465629 1844983380354327 1981...
result:
ok 663458 lines
Test #10:
score: 0
Accepted
time: 29ms
memory: 6876kb
input:
10 6417 8865 8038 110526694 628005299 673725902 446463582 112704833 707990331 271115006 361707491 914218378 464681407 99450964 392967886 773761049 9199268 977849225 874565557 867273259 189762259 175435645 152035061 896607326 935501113 134742704 393728811 226961721 855258439 523530185 725380028 20644...
output:
Case #1: 94409984009720 327812774780900 339773942287236 128988724526667 83520212824248 268554632597774 259264742 62367491661808 573255540917709 203180460495491 493950646216251 299474774795296 47435068421829 193377484828747 46590981198326 68358523188 547143314044444 334502831791363 564395650872523 74...
result:
ok 68706 lines
Test #11:
score: 0
Accepted
time: 564ms
memory: 40304kb
input:
10 49886 9668 62953 102367838 984289787 168856338 541798721 776619387 345431676 56009403 964549346 991967208 163705384 712516917 635203141 379755347 234257275 77347604 757892759 928436050 634059638 882024206 231008715 60943323 591400992 890471036 363743002 791551436 522451712 347781086 900241277 424...
output:
Case #1: 226732303164 628730980803431 30610877027234 3836094541013 37905476329605 442998467394948 135426951982122 424617384845724 2977588522010678 1039636522196302 6319208893864 4276315210005161 75549985706595 2331926668311364 3652811861727802 970063409678710 624293010772223 4633525893370803 9678964...
result:
ok 705663 lines
Test #12:
score: 0
Accepted
time: 480ms
memory: 34412kb
input:
10 52211 6992 58276 663493600 45813596 142955175 40185782 681313607 430868623 825027599 984603625 349142819 100951742 28484239 801388852 585637279 389430286 563809645 41015142 62915258 789346457 937365249 616361345 781074121 26745577 302568763 245467709 431680243 651386497 512669722 636160132 806386...
output:
Case #1: 2084414631374383 323341399626639 1710606768309713 470981344884239 3059422075513439 1319711226069600 2043508896766 983830863508087 36893998806987 168757634701068 545338661331903 235285117711711 1005476913698414 58423683476761 3138958646430576 2386857552941419 933565346046256 432515278569760 ...
result:
ok 669900 lines
Test #13:
score: 0
Accepted
time: 620ms
memory: 44792kb
input:
10 94175 9909 76432 467794768 393977076 78983874 874750194 987796677 755210742 493672308 448592408 470410600 351912881 97048577 696433604 226773254 316396987 178793840 747486293 638881666 997041630 390499357 773939617 662825297 585075867 38275639 529791856 379428861 939582370 463446081 976896 684564...
output:
Case #1: 1863562761934610 392491970668073 1118660135001562 2311815550703197 3454272312816981 6145830506274025 386814033241716 1115811573438162 6043997063628474 854792863624790 6248201006281378 2278972043075335 3962963493029238 1698865816769663 1663136656971164 1730551051855249 5582821973584267 77029...
result:
ok 669192 lines
Test #14:
score: 0
Accepted
time: 677ms
memory: 39476kb
input:
10 65885 5622 99362 988671338 151437667 1345638 842972516 843669710 456889639 850851586 922210568 899956481 275520249 633243114 556213669 751435200 658299352 665718637 46213661 132883209 522939048 212263515 122118518 743544735 262433458 28860041 415471962 606129546 629154338 922121041 69834904 27648...
output:
Case #1: 348745358122411 2108472338898585 806315597392324 4518667639511299 62627074789565 4618863458639242 1972209768208668 2513019471404295 933646823222788 869579321785690 844839817471361 3925652984799219 3229914932371950 836334080889819 2778140602904081 2683178211221088 367401567038211 11680311812...
result:
ok 831196 lines
Extra Test:
score: 0
Extra Test Passed