QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#663361#5549. Game Showucup-team3519#AC ✓71ms12588kbC++171.6kb2024-10-21 15:04:472024-10-21 15:04:48

Judging History

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

  • [2024-10-21 15:04:48]
  • 评测
  • 测评结果:AC
  • 用时:71ms
  • 内存:12588kb
  • [2024-10-21 15:04:47]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = int64_t;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, q;
    std::cin >> n >> q;

    std::vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        std::cin >> b[i];
    }
    a.insert(a.end(), a.begin(), a.end());
    b.insert(b.end(), b.begin(), b.end());

    bool flawed = false;
    for (int i = 0; i < n; ++i) {
        if (a[i] + b[i] < 0) {
            flawed = true;
            break;
        }
    }
    if (std::accumulate(a.begin(), a.end(), 0LL) < 0 ||
        std::accumulate(b.begin(), b.end(), 0LL) < 0) {
            flawed = true;
    }
    if (flawed) {
        for (int i = 0; i < q; ++i) {
            std::cout << "flawed\n";
        }
        return 0;
    }

    std::vector<i64> sa(n * 2), sb(n * 2);
    sa[0] = a[0];
    sb[0] = b[0];
    for (int i = 1; i < sa.size(); ++i) {
        sa[i] = sa[i - 1] + a[i];
        sb[i] = sb[i - 1] + b[i];
    }
    // std::partial_sum(a.begin(), a.end(), sa.begin());
    // std::partial_sum(b.begin(), b.end(), sb.begin());

    while (q--) {
        int s, t;
        std::cin >> s >> t;
        --s, --t;

        if (s == t) {
            std::cout << "0\n";
        } else {
            if (s > t) {
                t += n;
            }
            i64 ans = sa[t - 1] - (s ? sa[s - 1] : i64(0));
            if (s < t) {
                s += n;
            }
            ans = std::min(ans, sb[s - 1] - (t ? sb[t - 1] : i64(0)));
            std::cout << ans << '\n';
        }
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

4 4
2 3 -4 3
1 2 7 -1
1 3
3 1
1 4
1 1

output:

5
-1
-1
0

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

4 3
1 2 -3 4
4 -3 2 1
1 1
2 4
3 1

output:

flawed
flawed
flawed

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

6 2
-6 8 -3 5 -9 4
9 -2 8 -4 12 -1
2 6
3 3

output:

flawed
flawed

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

3 1
1 2 3
2 3 1
3 3

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3812kb

input:

119 14161
-471334480 -303286501 -823503521 204458352 428751472 -685555801 -315724979 454499825 326635838 274924560 623877126 -41230889 829726183 -901302108 -414222870 430105197 -163781582 -654097302 -785578511 634678229 -53714045 466578268 -156361557 31276696 778119895 744605022 -686693025 368251457...

output:

flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed...

result:

ok 14161 lines

Test #6:

score: 0
Accepted
time: 8ms
memory: 3672kb

input:

310 96100
995988008 -273572056 647506325 206645991 -449149473 -743958256 -263018073 522873394 -995870737 391893724 -602177324 912246319 -671361368 -339118861 787545510 276780215 150123420 -438281015 -486464371 -526419934 457117467 -340697687 -193705644 583522844 -862239080 -783668951 886284879 -2153...

output:

0
995988008
722415952
1369922277
1576568268
1127418795
383460539
120442466
643315860
-352554877
39338847
-562838477
349407842
-321953526
-661072387
126473123
403253338
553376758
115095743
-371368628
-897788562
-440671095
-781368782
-975074426
-391551582
-1253790662
-2037459613
-1151174734
-136653686...

result:

ok 96100 lines

Test #7:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

159 25281
571110069 497946045 215248224 285606755 -114253939 796175515 -214494926 -691740300 -694515306 425784607 -884181443 -417222365 -923910646 913088205 334337646 928400844 604137042 -251172024 -292361941 -243464366 315724262 -281093691 800734894 966549738 -939146974 -612753418 946191607 -701002...

output:

flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed...

result:

ok 25281 lines

Test #8:

score: 0
Accepted
time: 18ms
memory: 3560kb

input:

386 148996
-629374153 -930021329 -169749492 77888804 39969974 891272130 -96385962 -76492169 599659860 -779504873 921044785 937376141 597906327 -96821407 631221939 609871141 363156207 -866807335 -188422318 -528059242 964816522 314282210 -604961795 514941685 56630262 -956662135 343379714 218344584 -59...

output:

0
-629374153
-1559395482
-1729144974
-1651256170
-1611286196
-720014066
-816400028
-892892197
-293232337
-1072737210
-151692425
785683716
1383590043
1286768636
1917990575
2527861716
2891017923
2024210588
1835788270
1307729028
2272545550
2586827760
1981865965
2496807650
2553437912
1596775777
19401554...

result:

ok 148996 lines

Test #9:

score: 0
Accepted
time: 29ms
memory: 6916kb

input:

200000 200000
542641702 524593830 -670388831 -945604405 -364992596 191170051 -26787814 66913368 -262048292 -713493534 737457155 149980656 479874963 409329298 936423541 -409385368 410613548 -268647340 -209178559 -538810729 -311979646 896593511 -414858308 -508018786 166275960 712369177 113795469 81304...

output:

flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed...

result:

ok 200000 lines

Test #10:

score: 0
Accepted
time: 71ms
memory: 12588kb

input:

200000 200000
-859117315 241669988 515635146 -974661709 -565625054 -798417276 -544902983 -211538953 -243302276 336115744 -956543301 662011337 -791751745 318028077 -996636934 872505404 420483514 -375259846 126912462 494420432 523114793 -293956991 -989076221 387126868 -304945172 -581498983 -830472298 ...

output:

253349035948
311225694871
61702809599
505480747159
318262775201
328494991458
416520464677
243285217797
224189228033
279180960020
312970799627
347682772871
362965581804
203558820062
373599030300
431153864045
264323527787
176719325017
329753383539
585052004456
451387888964
431711406385
338423038272
32...

result:

ok 200000 lines

Test #11:

score: 0
Accepted
time: 45ms
memory: 7860kb

input:

100000 200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...

output:

1000000000
0
-1000000000
-2000000000
-3000000000
-4000000000
-5000000000
-6000000000
-7000000000
-8000000000
-9000000000
-10000000000
-11000000000
-12000000000
-13000000000
-14000000000
-15000000000
-16000000000
-17000000000
-18000000000
-19000000000
-20000000000
-21000000000
-22000000000
-230000000...

result:

ok 200000 lines

Test #12:

score: 0
Accepted
time: 66ms
memory: 12368kb

input:

200000 200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...

output:

99951000000000
99954000000000
99995000000000
99969000000000
99994000000000
99990000000000
99964000000000
99973000000000
99966000000000
99991000000000
99990000000000
99967000000000
99959000000000
99986000000000
99951000000000
99976000000000
99972000000000
99975000000000
99962000000000
99989000000000
...

result:

ok 200000 lines

Test #13:

score: 0
Accepted
time: 27ms
memory: 7072kb

input:

200000 200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...

output:

flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed...

result:

ok 200000 lines

Test #14:

score: 0
Accepted
time: 69ms
memory: 12460kb

input:

200000 200000
918023196 96461632 869831293 -807407070 556243762 534347218 840800033 -727901758 328367541 -805840542 -728163855 96436945 119365052 -488831892 -82532154 432548795 -98283674 453037664 418102986 460104469 588941197 721711740 -954753749 -35164942 292925043 980999687 369474604 281472856 -8...

output:

-32842628012
-29198570852
-19936603864
-736713879
-95967703728
49247141359
-38610448654
809185757
2798124645
-64300376469
-51394149939
127865383356
-25297949226
-45162129787
101758509026
16613087582
-293803684
-40625674519
-11532555818
-112383173294
-10470698318
-11367861564
-44333276344
-3677398500...

result:

ok 200000 lines

Test #15:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

3 2
1 2 3
2 3 1
1 2
2 1

output:

1
2

result:

ok 2 lines

Test #16:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

3 9
0 0 0
0 0 0
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

output:

0
0
0
0
0
0
0
0
0

result:

ok 9 lines

Test #17:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

3 9
5 -4 -1
-5 4 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

output:

0
5
1
-5
0
-4
-1
4
0

result:

ok 9 lines

Test #18:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

5 25
1 -3 -5 -7 3
7 10 44 3 5
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
2 4
2 5
3 1
3 2
3 3
3 4
3 5
4 1
4 2
4 3
4 4
4 5
5 1
5 2
5 3
5 4
5 5

output:

flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed

result:

ok 25 lines

Test #19:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

5 25
6 10 15 -6 -7
-5 -9 -14 6 8
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
2 4
2 5
3 1
3 2
3 3
3 4
3 5
4 1
4 2
4 3
4 4
4 5
5 1
5 2
5 3
5 4
5 5

output:

flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed

result:

ok 25 lines

Test #20:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

5 25
7 12 15 22 33
69 69 -42 69 69
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
2 4
2 5
3 1
3 2
3 3
3 4
3 5
4 1
4 2
4 3
4 4
4 5
5 1
5 2
5 3
5 4
5 5

output:

flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed

result:

ok 25 lines

Test #21:

score: 0
Accepted
time: 2ms
memory: 3592kb

input:

265 70225
185689233 205526741 89766355 247127393 -231236584 -404930790 -886574049 -454687411 583450067 57789843 136089128 851193267 -857927883 296343753 -263516925 914310309 -719298446 957236686 598317128 40954961 -763451153 279842034 889337838 43696656 -170676118 -470888777 548467373 -87699328 1368...

output:

flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed
flawed...

result:

ok 70225 lines

Test #22:

score: 0
Accepted
time: 13ms
memory: 3664kb

input:

334 111556
497576505 360231077 -524385517 591069494 -656293801 7867219 -101416704 -407515227 -391063191 771924531 678378242 -296258873 -524516353 476780676 4778913 110722520 885167206 -596964575 267995391 97038192 734578811 39285651 880419387 -302434682 501529728 399150123 -702341407 935931142 -7362...

output:

0
497576505
857807582
333422065
924491559
268197758
276064977
174648273
-232866954
-623930145
147994386
826372628
530113755
5597402
482378078
487156991
597879511
1483046717
886082142
1154077533
1251115725
1985694536
2024980187
2905399574
2602964892
3104494620
3503644743
2801303336
3737234478
3000938...

result:

ok 111556 lines