QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109353 | #70. Bitaro, who Leaps through Time | bashkort# | 0 | 2ms | 3928kb | C++20 | 4.7kb | 2023-05-28 18:19:32 | 2024-05-31 13:45:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 1e9 + 7;
struct SegmentTree {
vector<pair<int, int>> t;
vector<ll> ansL;
int sz = 1, N;
int cost(int x, int d, ll &ans) {
if (t[x].first <= t[x].second) {
ans += max(0, d - t[x].second);
return min(t[x].second, max(d, t[x].first));
} else if (t[x << 1].second == -inf) {
ans += ansL[x];
cost(x << 1, d, ans);
return t[x].first;
} else {
ans += max(0, d - t[x << 1].second);
return cost(x << 1 | 1, min(t[x << 1].second, max(d, t[x << 1].first)), ans);
}
}
void pull(int x) {
ansL[x] = 0;
if (t[x << 1].second == -inf) {
t[x].first = cost(x << 1 | 1, t[x << 1].first, ansL[x]);
} else if (t[x << 1 | 1].second == -inf) {
t[x] = t[x << 1 | 1];
} else {
if (t[x << 1].first > t[x << 1 | 1].second) {
t[x].first = t[x << 1 | 1].second;
t[x].second = -inf;
} else if (t[x << 1].second < t[x << 1 | 1].first) {
t[x].first = t[x << 1].first;
t[x].second = -inf;
} else {
t[x].first = max(t[x << 1].first, t[x << 1 | 1].first);
t[x].second = min(t[x << 1].second, t[x << 1 | 1].second);
assert(t[x].first <= t[x].second);
}
}
}
void init(int n, vector<int> L, vector<int> R) {
sz = 1 << __lg(n) + !!(n & (n - 1));
N = n;
t.resize(sz << 1), ansL.resize(sz << 1);
for (int i = 0; i < n; ++i) {
t[i + sz].first = L[i], t[i + sz].second = R[i];
}
for (int i = sz - 1; i > 0; --i) {
pull(i);
}
}
void rangeQuery(int l, int r, int &d, ll &ans, int x, int lx, int rx) {
if (l >= rx || lx >= r) {
return;
}
if (l <= lx && rx <= r) {
d = cost(x, d, ans);
return;
}
int mid = lx + rx >> 1;
rangeQuery(l, r, d, ans, x << 1, lx, mid);
rangeQuery(l, r, d, ans, x << 1 | 1, mid, rx);
}
ll rangeQuery(int l, int r, int &d) {
assert(l >= 0 && l < N && l < r && r <= N);
ll ans = 0;
rangeQuery(l, r, d, ans, 1, 0, sz);
return ans;
}
void modify(int x, int L, int R) {
x += sz;
t[x].first = L, t[x].second = R;
while (x >>= 1) {
pull(x);
}
}
};
//don't forget to add diff between d and needed time
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> L(n), R(n), AL(n), AR(n), BL(n), BR(n);
for (int i = 0; i < n - 1; ++i) {
cin >> L[i] >> R[i];
AL[i] = L[i] - i;
AR[i] = R[i] - i - 1;
BL[n - i - 2] = L[i] - (n - i - 2);
BR[n - i - 2] = R[i] - (n - i - 2) - 1;
}
SegmentTree A, B;
A.init(n - 1, AL, AR);
B.init(n - 1, BL, BR);
auto modify = [&](int i, int lx, int rx) {
L[i] = lx, R[i] = rx;
AL[i] = L[i] - i;
AR[i] = R[i] - i - 1;
BL[n - i - 2] = L[i] - (n - i - 2);
BR[n - i - 2] = R[i] - (n - i - 2) - 1;
A.modify(i, AL[i], AR[i]);
B.modify(n - i - 2, BL[n - i - 2], BR[n - i - 2]);
};
auto stupid = [](int x, int y, int a, int b, vector<int> &L, vector<int> &R) {
ll ans = 0;
for (int i = x; i < y; ++i) {
ans += max(0, a - R[i]);
a = min(R[i], max(a, L[i]));
}
ans += max(0, a - b);
return ans;
};
auto query = [&](int x, int a, int y, int b) -> ll {
if (x == y) {
return max(0, a - b);
}
ll ans = 0;
ll stup = 0;
if (x <= y) {
a -= x;
b -= y;
stup = stupid(x, y, a, b, AL, AR);
ans = A.rangeQuery(x, y, a);
} else {
a -= n - x - 1;
b -= n - y - 1;
stup = stupid(n - x - 1, n - y - 1, a, b, BL, BR);
ans = B.rangeQuery(n - x - 1, n - y - 1, a);
}
ans += max(0, a - b);
return stup;
return ans;
};
while (q--) {
int t;
cin >> t;
if (t == 1) {
int p, s, e;
cin >> p >> s >> e;
modify(p - 1, s, e);
} else {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << query(a - 1, b, c - 1, d) << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 4
Accepted
time: 1ms
memory: 3612kb
input:
20 18 115497790 671208773 326245299 528973482 100582193 437996818 89058008 771100620 768935396 842907844 187943946 997369106 455078418 542835554 536691525 970171971 564540350 570234421 657178750 753833933 386375484 979995375 389681484 772601117 634873482 897954663 87193815 139420775 259946990 394597...
output:
1155445816 286505553 517757980 236944355 561949186 106582836 0 304461403 191096499
result:
ok 9 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
15 17 799432943 881913223 498035324 890991779 221094434 725591919 122662663 205973504 27272780 296297777 291153744 738825389 687673889 832528078 137420041 553572552 537287355 667404293 78780696 511103623 286889731 428819824 739192588 933917861 640244010 719131850 8717351 484035792 2 11 677309334 6 6...
output:
178216662 974423743 0 481700389 733890120 758870349 1558763834 346029155 437727424 108467534 593459443 359706618 0
result:
ok 13 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
16 11 603825253 913320429 670886646 800039811 217352618 773699231 296579607 969388285 388940127 502044165 54269615 505520585 48521331 261246856 304031976 802908340 228375687 681572083 269930733 818118429 106359808 608054773 539957576 959284868 455951034 668855803 123057532 834760058 242484847 775646...
output:
88483329 105703091 464102733
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
15 11 908963840 980379860 482287588 649831101 38031090 465411687 533481152 831434174 406629282 988719404 397507510 949533408 35821579 713829876 228752296 587042290 275346816 817732210 488316500 975749664 20340939 619648576 126349631 719953399 218364365 556962137 6920451 301924386 2 6 945056726 15 49...
output:
643132349 155546242 155780531 16875903 310906172 0 0 195094969
result:
ok 8 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
17 12 64628557 835897857 48249381 434225831 88551966 200549208 229517981 588326677 541856941 616513968 601727245 629061465 127214422 908476391 113489767 518731381 651615013 985313204 7844300 821451341 191392243 811053095 414007157 749815863 609391664 809840876 808162469 982212585 260950534 914552673...
output:
549935960 696417081 661847876 539200339 293586522
result:
ok 5 lines
Test #6:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
19 19 447087687 936531339 53854884 599216443 694038961 733581758 158339761 929655849 193659077 329609020 27443904 94886943 77676648 337260078 488783350 780397744 235987783 882435678 424296902 927171276 495053187 586947183 789027929 866336724 132785532 827723754 585565933 850125599 503266414 97479355...
output:
277545715 257890264 1112835993 212665987 374743372 256371719 478951983 408249275 804719793 22031677
result:
ok 10 lines
Test #7:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
17 13 152099374 640797743 42073954 787394185 612427905 690229699 399369071 529294970 258683205 933584740 742906725 928112367 515162235 595008674 813704059 870926387 372056021 806836222 749972071 896947506 627864088 794561704 424101490 556641442 150167093 235631429 214680035 376800755 421019185 49865...
output:
571475615 600069983 32256238 687447329 557147913 1036027557 551213708
result:
ok 7 lines
Test #8:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
20 19 373541951 505416797 262774005 988470528 587455394 881023049 109591789 240106849 32306391 154829124 799230608 846139786 624167918 840851478 809131207 989196724 634052813 722821356 113862966 589268597 102764697 815576034 163438394 991020003 659264094 918509025 56179386 718956825 193882392 214621...
output:
604201446 1097131362 0 654302087 1097174101 652613474 19083093 0 494275835 576864970 1184277076 1280691303 1688357480
result:
ok 13 lines
Test #9:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
14 14 156376628 557797505 180222176 223890495 35590627 721337980 692250789 871735221 878092062 999364145 212733464 329284176 30942314 104213638 105541580 127848961 241963698 805113153 376711068 884708233 283663894 306206250 531134850 803356496 219402922 599680441 2 1 725445177 11 641767981 1 11 3478...
output:
1275433111 913209939 426921218 243465064 1602620612 754838212 517800605
result:
ok 7 lines
Test #10:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
12 19 79254705 484475172 180868149 422648245 786812722 894467885 44514142 698514528 6765752 402358366 739120575 879508240 850722303 854054325 411799340 748102244 10282220 320131379 794809243 804491888 417234308 907277041 2 4 255211884 3 897643005 1 6 38562091 921655105 2 12 524457416 2 539520012 2 4...
output:
0 1287206285 276546582 1367872448 415662172 0 530590927 0 941784740 0 442863848 724611207 344952127
result:
ok 13 lines
Test #11:
score: 0
Accepted
time: 2ms
memory: 3928kb
input:
805 1000 394061362 572700408 468706606 784691393 68754531 426219159 104560631 159226823 355534999 633842543 208012936 691894625 296423122 536492314 89122231 868143488 642577421 937810973 943293106 952789137 282906225 682715734 650898223 984158253 450869600 946943479 745941543 904346065 450176376 875...
output:
21592593375 18785195874 12169688094 30720051851 0 3393708145 15292503574 10353860634 15465614721 1062642207 8845686587 33738104860 5721603820 15579189570 43085728428 16847313941 2210883517 18642147758 12559630669 4694961787 34461410220 44940939646 17778377601 18967720166 15225981328 4783466527 21409...
result:
ok 504 lines
Test #12:
score: -4
Runtime Error
input:
956 1000 583440066 936410875 9650169 79289067 157406340 986440994 595500197 994801731 578308109 999558680 133108595 726565856 200185481 408617812 647019681 819465584 131392370 450135424 89148674 361839727 321344622 895313145 581181878 589716501 350657421 988659300 734325332 864012556 131750527 90502...
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #42:
score: 0
Time Limit Exceeded
input:
274318 300000 489215489 676617321 780126019 788585486 556851007 580284394 233372413 595198772 519202713 898223077 502895565 696411826 206200999 769856900 270143414 346344669 729812429 901771242 663771137 938786194 472985796 990513077 846601694 992055636 178982840 919444964 27052680 316046043 8183731...
output:
2849147975708 3843046238428 4095601609850 9126786831492 441666160010 4429060670616 6742720280622 10766622641576 588806818956 4531560125304 3895414541258 8791722334108 6126584591501 6704860308139 6957107549525 7807342130069 46968789226 1110092057560 2141002313351 5188051547992 446258629063 5203914165...
result:
Subtask #3:
score: 0
Runtime Error
Test #56:
score: 0
Runtime Error
input:
270695 300000 513123795 772355425 210106247 394028231 276162603 911454418 105669187 977348162 173662950 272706156 152814457 669922258 344843731 523572913 316675910 752220119 109044474 322732409 555169512 652867118 622530606 779759913 153668285 339269709 150911093 937002300 186921016 855255616 118867...
output:
6546523326977 1147915030312 9771877069345 1119704562225 3602711301295 3345329466188 8703715133673 1212731543002 3001190474356 6022602583263 10932431457685 3426986196964 5639811302245 4279224529757 4905678737163 2895778161036 5881977936447 10163872384436 2379437009373 5875928707705 7679043988101 4490...