QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#489804 | #70. Bitaro, who Leaps through Time | thangthang | 0 | 863ms | 80928kb | C++20 | 3.4kb | 2024-07-25 01:50:31 | 2024-07-25 01:50:31 |
Judging History
answer
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N = 3e5 + 5;
const long long inf = -1e18;
struct Node{
long long val[2][2];
Node(){
for (int i = 0; i < 2; ++ i)
for (int j = 0; j < 2; ++ j) val[i][j] = inf;
val[0][0] = 0;
}
};
Node mer(Node a, Node b){
Node c;
for (int i = 0; i < 2; ++ i){
for (int j = 0; j < 2; ++ j) c.val[i][j] = max(a.val[i][j], b.val[i][j]);
}
for (int i = 0; i < 2; ++ i){
for (int l = 0; l < 2; ++ l){
for (int j = 0; j < 2; ++ j) c.val[i][j] = max(c.val[i][j], a.val[i][l] + b.val[l][j]);
}
}
return c;
}
struct Segtree{
Node it[4 * N];
void update(int s, int l, int r, int u, int i, int j){
//if (i == j && i == 3 && u == 3) cout << l << ' ' << r << ' ' << u << endl;
if (l == r){
it[s].val[0][0] = 0;
it[s].val[1][0] = l - j;
it[s].val[0][1] = i - l;
return;
}
int mid = l + r >> 1;
if (mid >= u) update(2 * s, l, mid, u, i, j);
else update(2 * s + 1, mid + 1, r, u, i, j);
it[s] = mer(it[2 * s], it[2 * s + 1]);
}
Node get(int s, int l, int r, int u, int v){
if (u <= l && r <= v) return it[s];
int mid = l + r >> 1;
Node a, b;
int bl = 0, br = 0;
if (mid >= u) a = get(2 * s, l, mid, u, v), bl = 1;
if (mid + 1 <= v) b = get(2 * s + 1, mid + 1, r, u, v), br = 1;
if (!bl) return b;
if (!br) return a;
return mer(a, b);
}
} seg1, seg2;
int in[N], out[N], n, q;
void solve(){
cin >> n >> q;
for (int i = 1; i <= n - 1; ++ i){
cin >> in[i] >> out[i];
seg1.update(1, 0, n, i, in[i], out[i] - 1);
seg2.update(1, 0, n, n - i, in[i], out[i] - 1);
}
while (q --){
int t; cin >> t;
if (t & 1){
int i; cin >> i;
cin >> in[i] >> out[i];
seg1.update(1, 0, n, i, in[i], out[i] - 1);
seg2.update(1, 0, n, n - i, in[i], out[i] - 1);
}
else {
int s, ts, e, te;
cin >> s >> ts >> e >> te;
if (s <= e){
seg1.update(1, 0, n, s - 1, ts - 1, ts - 1);
seg1.update(1, 0, n, e, te, te);
//cout << t << ' ' << s << ' ' << ts << ' ' << e << ' ' << te endl;
//cout << it[7].val[1][0] << endl;
cout << seg1.get(1, 0, n, s - 1, e).val[0][0] << '\n';
seg1.update(1, 0, n, s - 1, in[s - 1], out[s - 1] - 1);
seg1.update(1, 0, n, e, in[e], out[e] - 1);
}
else {
swap(s, e);
seg2.update(1, 0, n, n - e, ts - 1, ts - 1);
seg2.update(1, 0, n, n - s + 1, te, te);
//cout << n - e << ' ' << ts - 1 << ' ' << ts - 1 << endl;
//for (int i = n - e + 1; i < n - s + 1; ++ i) cout << i << ' ' << in[n - i] << ' ' << out[n - i] - 1 << endl;
//cout << n - s + 1 << ' ' << te << ' ' << te << endl;
cout << seg2.get(1, 0, n, n - e - 1, n + 1 - s).val[0][0] << '\n';
seg2.update(1, 0, n, n - e, in[e], out[e] - 1);
seg2.update(1, 0, n, n + 1 - s, in[s - 1], out[s - 1] - 1);
}
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 80004kb
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 61972066 304461403 191096499
result:
wrong answer 7th lines differ - expected: '0', found: '61972066'
Subtask #2:
score: 0
Wrong Answer
Test #42:
score: 0
Wrong Answer
time: 863ms
memory: 80928kb
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 6742971086263 10766622641576 588806818956 4531791536316 3895414541258 8791722334108 6126584591501 6704860308139 6957107549525 7807855878924 46968789226 1110092057560 2141002313351 5188051547992 446258629063 5203914165...
result:
wrong answer 7th lines differ - expected: '6742720280622', found: '6742971086263'
Subtask #3:
score: 0
Wrong Answer
Test #56:
score: 0
Wrong Answer
time: 725ms
memory: 80892kb
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 1119835954112 3602711301295 3345329466188 8703715133673 1212731543002 3001190474356 6022602583263 10932431457685 3427001464292 5639811302245 4279224529757 4905678737163 2895778161036 5882608067294 10163872384436 2379437009373 5875928707705 7679043988101 4490...
result:
wrong answer 4th lines differ - expected: '1119704562225', found: '1119835954112'