QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#267325 | #3272. 简单数据结构 | KHIN# | 30 | 42ms | 20148kb | C++17 | 2.0kb | 2023-11-27 09:28:33 | 2024-07-04 03:08:50 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
constexpr long N(200'000);
constexpr long Q(200'000);
struct event {
long op, v, l, r;
};
long n, q;
long a[N + 1];
long s[N + 1];
event e[Q + 1];
vector<long> id1;
long cnt[Q + 1];
long prv[Q + 1];
long sum[Q + 1];
vector<pair<long, long>> upd[N + 1];
long ans[Q + 1];
inline long clc(long const i, long const x)
{ return e[prv[x]].v + i * (cnt[x] - cnt[prv[x]]); }
int main() {
cin >> n >> q;
for (long i(1); i <= n; ++i) cin >> a[i];
partial_sum(a + 1, a + n + 1, s + 1);
for (long i(1); i <= q; ++i) {
switch (cin >> e[i].op, e[i].op) {
case 1: cin >> e[i].v; break;
case 2: break;
case 3: cin >> e[i].l >> e[i].r; break;
}
if (e[i].op == 1) id1.push_back(i);
cnt[i] = cnt[i - 1] + (e[i].op == 2);
if (e[i].op == 3) {
long const l(e[i].l - 1);
long const r(e[i].r - 0);
upd[l].emplace_back(i, +1);
upd[r].emplace_back(i, -1);
ans[i] += s[r] - s[l];
ans[i] += (l + r + 1) * (r - l) / 2 * cnt[i];
}
}
if (!id1.empty()) {
for (long i(id1.front()); i <= q; ++i)
prv[i] = id1.front();
for (long i(1); i <= n; ++i) {
// cerr << "clc" << ' ' << i << '\n';
for (long const j : id1) if (clc(i, j) > e[j].v) {
// cerr << "ins" << ' ' << j << '\n';
for (long k(j); k <= q && prv[k] < j; ++k) prv[k] = j;
}
long l(-1), r(id1.size());
while (r - l > 1) {
long const m((l + r) / 2);
(a[i] + i * cnt[id1.at(m)] < clc(i, id1.at(m)) ? l : r) = m;
}
long const p(r == long(id1.size()) ? q + 1 : id1.at(r));
// cerr << "partition" << ' ' << p << '\n';
for (long j(p); j <= q; ++j)
sum[j] += a[i] + i * cnt[prv[j]] - e[prv[j]].v;
for (auto const& j : upd[i]) ans[j.first] += j.second * sum[j.first];
}
}
for (long i(1); i <= q; ++i)
if (e[i].op == 3)
cout << ans[i] << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 41ms
memory: 18104kb
input:
5000 5000 29940 259997 53132 912489 608312 594283 432259 344137 889466 383028 320097 337418 571199 372832 563110 542407 133378 998389 238387 120880 477310 634888 191990 133585 935315 558139 141724 893331 190118 991968 843042 384930 935256 891482 123419 91431 955722 376987 197566 106433 234494 645967...
output:
512185934 455189773 121665669 408693244 291779262 45671866 242375008 302245547 222004631 41963113 343434445 347127029 183849524 2144625 278637672 220461451 20719635 108759503 22099550 34631220 55848925 92362584 36949030 86469096 43509864 50829332 1334865 76069109 114623436 13564322 79974466 15230088...
result:
ok 1671 numbers
Test #2:
score: 0
Accepted
time: 37ms
memory: 16084kb
input:
5000 5000 754848159362 799142221874 945332296572 929342054343 220343371940 207059247564 870301066785 609144766745 830351478389 198801101804 768950635554 592202774571 800496073014 730985048260 581401590014 934021096780 587980626010 77068543347 206074783770 390850923112 122794404396 281461236458 11092...
output:
116508179221533 546749128093796 194349368397972 39703523008217 175276724949769 115828286259777 53486037590699 32085609121169 79863137176116 53634397678952 11984901865039 53065256000101 29045072084569 26415198892331 75111789355520 75384800485844 34569350111656 133340053405484 51324651695791 973372919...
result:
ok 1647 numbers
Test #3:
score: 0
Accepted
time: 41ms
memory: 16100kb
input:
5000 5000 2572389899 2379766449 7410864819 2850299650 5617053831 3824312403 9814616879 8435146331 612453351 6111276232 7985477358 2776770282 2475123938 8017080204 7914003508 932800576 1394850160 1615934603 2716519725 6482033755 4787594046 7431658437 9394772703 5567857454 8294657000 2254310003 522061...
output:
10215584720705 1705389861 345800268 2011341781 2308552335 292528530 262542520 978988815 1435722498 941192965 986070818 873158540 1424652645 128856850 1383766618 1238322582 1869688874 820493117 1165528560 1332973518 2307494520 999182443 932104492 823277168 1062040845 1227853390 1624003330 1769087853 ...
result:
ok 1677 numbers
Test #4:
score: 0
Accepted
time: 37ms
memory: 16136kb
input:
5000 5000 999809 999517 999488 999380 999248 998857 998620 998604 998567 998308 998186 997997 997810 997577 997322 997020 996746 996534 996197 995855 995826 995640 995600 995210 995081 994967 994685 994625 994443 994442 994262 993784 993725 993555 993306 993103 993081 992995 992414 991911 991909 991...
output:
16773634 412440775 172002115 859804112 771558481 736128415 379732036 26069114 230547108 124250573 144893959 16706694 204005800 25688354 45410890 426029778 358724432 507488261 286534500 26563180 474284154 22346892 56002662 236061693 295241526 137542524 22942480 293165763 323726733 160884504 192510432...
result:
ok 1650 numbers
Test #5:
score: 0
Accepted
time: 42ms
memory: 14540kb
input:
5000 5000 29989 29976 29976 29973 29966 29964 29960 29959 29950 29950 29943 29942 29939 29934 29931 29921 29914 29898 29873 29853 29845 29839 29833 29823 29793 29789 29779 29767 29765 29763 29759 29743 29742 29727 29724 29717 29711 29711 29710 29709 29709 29705 29695 29692 29687 29683 29678 29673 29...
output:
1677454 842408 7914094 20958765 1919270 1922628 25681578 7752212 4645740 4828824 44635274 4507503 10332327 943492 14007222 24519700 6369696 10888484 8301980 21731014 46268553 396 671 5698 12727 10692 121644 1954398 26911503 6554385 672220 8506939 3468479 3589800 9368964 17529036 9895900 4797296 6049...
result:
ok 1647 numbers
Test #6:
score: 0
Accepted
time: 3ms
memory: 16008kb
input:
5000 500 29995 29990 29989 29988 29985 29981 29976 29971 29964 29937 29930 29922 29919 29910 29883 29883 29866 29864 29855 29855 29850 29843 29842 29836 29834 29828 29827 29821 29820 29819 29819 29818 29817 29814 29800 29799 29798 29794 29783 29777 29769 29765 29758 29754 29750 29745 29741 29741 297...
output:
29842583 9940497 16817240 29922210 13110978 400953 90403379 2520804 5008146 8960380 3019016 10404797 2657305 48660920 16149760 15343500 41648193 29264570 13432320 11089916 14534100 24971099 6748971 9015984 10408641 16352180 4234968 14245138 15540872 8479523 1054657 11951303 1314467 20398020 3903982 ...
result:
ok 159 numbers
Test #7:
score: 0
Accepted
time: 8ms
memory: 14516kb
input:
500 5000 29998 29894 29881 29844 29816 29792 29788 29741 29403 29329 29188 29184 29044 29039 28923 28878 28667 28624 28578 28567 28397 28374 28266 28233 28185 28120 28078 27835 27806 27778 27770 27769 27501 27475 27387 27320 27318 27209 27188 27183 27173 27125 27005 26977 26972 26949 26927 26784 267...
output:
101428 529856 311680 1060052 1284458 1226856 517734 141825 690886 1436243 203775 8910 110817 371700 196416 294690 543780 541581 126474 545259 91364 399750 635400 380254 32571 989562 786370 25752 67921 22420 99330 155855 69388 338997 150689 187210 550625 194129 23481 662186 343232 75411 225330 155133...
result:
ok 1622 numbers
Subtask #2:
score: 20
Accepted
Subtask #3:
score: 0
Time Limit Exceeded
Test #1:
score: 15
Accepted
time: 40ms
memory: 16140kb
input:
5000 5000 29940 259997 53132 912489 608312 594283 432259 344137 889466 383028 320097 337418 571199 372832 563110 542407 133378 998389 238387 120880 477310 634888 191990 133585 935315 558139 141724 893331 190118 991968 843042 384930 935256 891482 123419 91431 955722 376987 197566 106433 234494 645967...
output:
512185934 455189773 121665669 408693244 291779262 45671866 242375008 302245547 222004631 41963113 343434445 347127029 183849524 2144625 278637672 220461451 20719635 108759503 22099550 34631220 55848925 92362584 36949030 86469096 43509864 50829332 1334865 76069109 114623436 13564322 79974466 15230088...
result:
ok 1671 numbers
Test #2:
score: 0
Accepted
time: 34ms
memory: 20148kb
input:
5000 5000 754848159362 799142221874 945332296572 929342054343 220343371940 207059247564 870301066785 609144766745 830351478389 198801101804 768950635554 592202774571 800496073014 730985048260 581401590014 934021096780 587980626010 77068543347 206074783770 390850923112 122794404396 281461236458 11092...
output:
116508179221533 546749128093796 194349368397972 39703523008217 175276724949769 115828286259777 53486037590699 32085609121169 79863137176116 53634397678952 11984901865039 53065256000101 29045072084569 26415198892331 75111789355520 75384800485844 34569350111656 133340053405484 51324651695791 973372919...
result:
ok 1647 numbers
Test #3:
score: 0
Accepted
time: 41ms
memory: 16032kb
input:
5000 5000 2572389899 2379766449 7410864819 2850299650 5617053831 3824312403 9814616879 8435146331 612453351 6111276232 7985477358 2776770282 2475123938 8017080204 7914003508 932800576 1394850160 1615934603 2716519725 6482033755 4787594046 7431658437 9394772703 5567857454 8294657000 2254310003 522061...
output:
10215584720705 1705389861 345800268 2011341781 2308552335 292528530 262542520 978988815 1435722498 941192965 986070818 873158540 1424652645 128856850 1383766618 1238322582 1869688874 820493117 1165528560 1332973518 2307494520 999182443 932104492 823277168 1062040845 1227853390 1624003330 1769087853 ...
result:
ok 1677 numbers
Test #4:
score: 0
Accepted
time: 37ms
memory: 16148kb
input:
5000 5000 999809 999517 999488 999380 999248 998857 998620 998604 998567 998308 998186 997997 997810 997577 997322 997020 996746 996534 996197 995855 995826 995640 995600 995210 995081 994967 994685 994625 994443 994442 994262 993784 993725 993555 993306 993103 993081 992995 992414 991911 991909 991...
output:
16773634 412440775 172002115 859804112 771558481 736128415 379732036 26069114 230547108 124250573 144893959 16706694 204005800 25688354 45410890 426029778 358724432 507488261 286534500 26563180 474284154 22346892 56002662 236061693 295241526 137542524 22942480 293165763 323726733 160884504 192510432...
result:
ok 1650 numbers
Test #5:
score: 0
Accepted
time: 42ms
memory: 16100kb
input:
5000 5000 29989 29976 29976 29973 29966 29964 29960 29959 29950 29950 29943 29942 29939 29934 29931 29921 29914 29898 29873 29853 29845 29839 29833 29823 29793 29789 29779 29767 29765 29763 29759 29743 29742 29727 29724 29717 29711 29711 29710 29709 29709 29705 29695 29692 29687 29683 29678 29673 29...
output:
1677454 842408 7914094 20958765 1919270 1922628 25681578 7752212 4645740 4828824 44635274 4507503 10332327 943492 14007222 24519700 6369696 10888484 8301980 21731014 46268553 396 671 5698 12727 10692 121644 1954398 26911503 6554385 672220 8506939 3468479 3589800 9368964 17529036 9895900 4797296 6049...
result:
ok 1647 numbers
Test #6:
score: 0
Accepted
time: 4ms
memory: 15932kb
input:
5000 500 29995 29990 29989 29988 29985 29981 29976 29971 29964 29937 29930 29922 29919 29910 29883 29883 29866 29864 29855 29855 29850 29843 29842 29836 29834 29828 29827 29821 29820 29819 29819 29818 29817 29814 29800 29799 29798 29794 29783 29777 29769 29765 29758 29754 29750 29745 29741 29741 297...
output:
29842583 9940497 16817240 29922210 13110978 400953 90403379 2520804 5008146 8960380 3019016 10404797 2657305 48660920 16149760 15343500 41648193 29264570 13432320 11089916 14534100 24971099 6748971 9015984 10408641 16352180 4234968 14245138 15540872 8479523 1054657 11951303 1314467 20398020 3903982 ...
result:
ok 159 numbers
Test #7:
score: 0
Accepted
time: 8ms
memory: 16112kb
input:
500 5000 29998 29894 29881 29844 29816 29792 29788 29741 29403 29329 29188 29184 29044 29039 28923 28878 28667 28624 28578 28567 28397 28374 28266 28233 28185 28120 28078 27835 27806 27778 27770 27769 27501 27475 27387 27320 27318 27209 27188 27183 27173 27125 27005 26977 26972 26949 26927 26784 267...
output:
101428 529856 311680 1060052 1284458 1226856 517734 141825 690886 1436243 203775 8910 110817 371700 196416 294690 543780 541581 126474 545259 91364 399750 635400 380254 32571 989562 786370 25752 67921 22420 99330 155855 69388 338997 150689 187210 550625 194129 23481 662186 343232 75411 225330 155133...
result:
ok 1622 numbers
Test #8:
score: -15
Time Limit Exceeded
input:
200000 200000 230887273973 981603875652 113292402721 438678940199 836631032882 266043112082 527547838654 732594084126 329246064377 369715767534 658438750450 410647482510 267084058934 877638442790 42545402543 840640973131 524426029052 933194442797 563955124048 700439032209 703056463665 314702014994 2...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%