QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#863552#70. Bitaro, who Leaps through Timelichenyu_ac0 725ms43228kbC++143.0kb2025-01-19 19:14:092025-01-19 19:14:09

Judging History

你现在查看的是最新测评结果

  • [2025-01-19 19:14:09]
  • 评测
  • 测评结果:0
  • 用时:725ms
  • 内存:43228kb
  • [2025-01-19 19:14:09]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int N = 3e5 + 10, INF = 0x3f3f3f3f;

int n, m;
pair<int, int> a[N];

struct Data {
    int l, r; ll val;
    Data(int l = -INF, int r = INF, int val = -1) : l(l), r(r), val(val) {}
};

Data merge(const Data& x, const Data& y) {
    if (x.val == -1 && y.val == -1) {
        if (x.l > y.r) return Data(x.l, y.r, x.l - y.r);
        if (x.r < y.l) return Data(x.r, y.l, 0);
        return Data(max(x.l, y.l), min(x.r, y.r));
    }
    if (x.val == -1) {
        if (y.l < x.l) return Data(x.l, y.r, y.val + x.l - y.l);
        if (y.l > x.r) return Data(x.r, y.r, y.val);
        return y;
    }
    if (y.val == -1) {
        if (x.r > y.r) return Data(x.l, y.r, x.val + x.r - y.r);
        if (x.r < y.l) return Data(x.l, y.l, x.val);
        return x;
    }
    return Data(x.l, y.r, x.val + y.val + max(0, x.r - y.l));
}

struct SegmentTree {
    #define lc (p << 1)
    #define rc (p << 1 | 1)
    #define mid ((L + R) >> 1)

    Data dat[N << 2];
    void upd(int p) {dat[p] = merge(dat[lc], dat[rc]);}

    void change(int p, int L, int R, int x, Data k) {
        if (L == R) {
            dat[p] = k;
            return;
        }
        if (x <= mid) change(lc, L, mid, x, k);
        else change(rc, mid + 1, R, x, k);
        upd(p);
    }

    Data ask(int p, int L, int R, int l, int r) {
        if (l <= L && R <= r) return dat[p];
        if (r <= mid) return ask(lc, L, mid, l, r);
        else if (l > mid) return ask(rc, mid + 1, R, l, r);
        else return merge(ask(lc, L, mid, l, r), ask(rc, mid + 1, R, l, r));
    }
    #undef lc
    #undef rc
    #undef mid
} T[2];

int main() {
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        cin >> a[i].fi >> a[i].se;
        T[0].change(1, 1, n - 1, i, Data(a[i].fi - i, a[i].se - i - 1));
    }
    reverse(a + 1, a + n);
    for (int i = 1; i < n; i++) 
        T[1].change(1, 1, n - 1, i, Data(a[i].fi - i, a[i].se - i - 1));
    while (m--) {
        int op;
        cin >> op;
        if (op == 1) {
            int x, l, r; cin >> x >> l >> r;
            T[0].change(1, 1, n - 1, x, Data(l - x, r - x - 1));
            x = n - x;
            T[1].change(1, 1, n - 1, x, Data(l - x, r - x - 1));
        } else if (op == 2) {
            int a, b, c, d; cin >> a >> b >> c >> d;
            if (a == c) cout << max(0, b - d) << endl;
            else if (a < c) {
                Data now = T[0].ask(1, 1, n - 1, a, c - 1);
                now = merge(Data(b - a, b - a), now);
                now = merge(now, Data(d - c, d - c));
                cout << now.val << endl;
            } else {
                a = n - a + 1, c = n - c + 1;
                Data now = T[1].ask(1, 1, n - 1, a, c - 1);
                now = merge(Data(b - a, b - a), now);
                now = merge(now, Data(d - c, d - c));
                cout << now.val << endl;
            }
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 4
Accepted
time: 1ms
memory: 42880kb

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: 4
Accepted
time: 0ms
memory: 42824kb

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: 4
Accepted
time: 2ms
memory: 41544kb

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: 4
Accepted
time: 2ms
memory: 42760kb

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: 4
Accepted
time: 0ms
memory: 41772kb

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: 4
Accepted
time: 4ms
memory: 41268kb

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: 4
Accepted
time: 1ms
memory: 43160kb

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: 4
Accepted
time: 1ms
memory: 42988kb

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: 4
Accepted
time: 1ms
memory: 42748kb

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: 4
Accepted
time: 5ms
memory: 42280kb

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
Wrong Answer
time: 3ms
memory: 42528kb

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:

117756895
1605326690
-715213794
655280779
0
-901259151
-1887365610
1763926042
-1714254463
1062642207
255751995
-621633508
1426636524
-1600679614
136055468
-332555243
-2084083779
1462278574
-325271219
399994491
101671852
1991266686
598508417
1787850982
-1953887856
488499231
-65221247
-1645814641
1631...

result:

wrong answer 1st lines differ - expected: '21592593375', found: '117756895'

Subtask #2:

score: 0
Wrong Answer

Test #42:

score: 0
Wrong Answer
time: 725ms
memory: 43188kb

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:

1584658460
-949491492
-1797190534
-18672508
-715471478
949388440
-378374098
-860369496
396299404
369628024
-120796214
-75720804
1961227405
416359083
-739469995
-908414059
-275851030
1990495192
2108599943
-268945576
-417969721
-1586197493
-1692505291
-351325470
-657849065
671689254
1623662293
1059569...

result:

wrong answer 1st lines differ - expected: '2849147975708', found: '1584658460'

Subtask #3:

score: 0
Wrong Answer

Test #56:

score: 0
Wrong Answer
time: 690ms
memory: 43228kb

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:

993167873
1158762280
826470945
-1281902031
-766260049
-450057396
2111391977
1550765530
-991665548
1058434271
1739689365
-397705244
519242597
1437102941
826085131
970203532
-2127259073
1979762100
25127389
413446777
-357537147
-1938023975
1854527212
-1404839306
-148365771
127410017
1885980952
82103933...

result:

wrong answer 1st lines differ - expected: '6546523326977', found: '993167873'