QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#761570#3509. Ants and SugarWansur16 727ms950908kbC++202.1kb2024-11-19 00:54:492024-11-19 00:54:51

Judging History

This is the latest submission verdict.

  • [2024-11-19 00:54:51]
  • Judged
  • Verdict: 16
  • Time: 727ms
  • Memory: 950908kb
  • [2024-11-19 00:54:49]
  • Submitted

answer

#include <bits/stdc++.h>
#define ent '\n'
#define int long long

using namespace std;
typedef long long ll;

const int maxn = 5e5 + 12;
const int mod = 998244353;

int n, m, k;

struct asd {
    int dp[2][2];
    int lx, rx;
    int ly, ry;

    asd() {
        dp[0][0] = dp[1][0] = dp[0][1] = dp[1][1] = 0;
        lx = rx = 0;
    }
};

asd merge(asd x, asd y) {
    asd ans;
    ans.lx = x.lx, ans.rx = y.rx;
    ans.ly = x.ly, ans.ry = y.ry;
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            ans.dp[i][j] = min(x.dp[i][1] + y.dp[1][j] - x.ry, min(x.dp[i][0], x.dp[i][1]) + min(y.dp[0][j], y.dp[1][j]));
        }
    }
    return ans;
}


asd t[maxn * 30];
int L[maxn * 30], R[maxn * 30];
int nv = 1;

void upd(int v, int tl, int tr, int pos, int x, int tp) {
    if(tl == tr) {
        if(!tp) {
            t[v].lx += x;
            t[v].rx += x;
        }
        else {
            if(tp < 0) {
                t[v].ly += x;
            }
            else {
                t[v].ry += x;
            }
        }
        t[v].dp[0][1] = 1e18;
        t[v].dp[1][0] = 1e18;
        t[v].dp[1][1] = t[v].ly + t[v].ry - t[v].lx;
        return;
    }
    int mid = tl + tr >> 1;
    if(!L[v]) {
        L[v] = ++nv;
    }
    if(!R[v]) {
        R[v] = ++nv;
    }
    if(pos <= mid) {
        upd(L[v], tl, mid, pos, x, tp);
    }
    else {
        upd(R[v], mid + 1, tr, pos, x, tp);
    }
    t[v] = merge(t[L[v]], t[R[v]]);
}

void solve() {
    cin >> n >> k;
    m = (1 << 30) - 1;
    int sum = 0;
    while(n--) {
        int tp, pos, x;
        cin >> tp >> pos >> x;
        if(tp == 2) {
            upd(1, 0, m, pos / 2, x, 0);
            sum += x;
        }
        else {
            upd(1, 0, m, pos / 2, x, 1);
            upd(1, 0, m, pos / 2 + 1, x, -1);
        }
        cout << sum + min({t[1].dp[0][0], t[1].dp[1][0], t[1].dp[0][1], t[1].dp[1][1]}) << ent;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;

    while(t--) {
        solve();
    }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 40ms
memory: 942592kb

input:

1 1
1 1 43789532

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Wrong Answer
time: 31ms
memory: 942396kb

input:

2059 1
2 91 205759686
2 2689 599484232
1 2180 81617884
2 1782 293164452
2 1295 83799395
1 824 576761628
2 2942 522567248
2 2573 662719421
2 2570 691955288
1 2656 419809596
1 2225 256640321
1 2171 737201459
1 586 819276893
1 2368 699662246
1 738 914000324
2 2758 745510056
1 2108 122277545
1 1409 9821...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
417894923
417894923
417894923
417894923
417894923
644411044
644411044
644411044
644411044
644411044
644411044
644411044
644411044
644411044
644411044
644411044
87...

result:

wrong answer 70th lines differ - expected: '0', found: '417894923'

Subtask #2:

score: 16
Accepted

Test #22:

score: 16
Accepted
time: 40ms
memory: 941696kb

input:

1 1
2 0 424230929

output:

0

result:

ok single line: '0'

Test #23:

score: 16
Accepted
time: 492ms
memory: 948760kb

input:

362674 1
1 319945 761268318
1 277089 817774990
2 18206 713581467
2 142742 89669841
2 102420 421037684
2 114708 529878465
2 293986 64855921
2 339668 633637695
1 320879 569859555
1 241581 2375253
1 210995 379413808
1 63811 2383494
2 12768 261151784
2 180138 450721176
2 96696 419034251
2 97996 46059421...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 362674 lines

Test #24:

score: 16
Accepted
time: 286ms
memory: 945492kb

input:

239785 1
2 119892 999999821
1 119893 999999166
1 119891 999999900
2 119894 999999762
2 119890 999999172
1 119895 999999318
1 119889 999999983
2 119896 999999293
2 119888 999999633
1 119897 999999758
1 119887 999999146
2 119898 999999279
2 119886 999999192
1 119899 999999658
1 119885 999999552
2 1199...

output:

0
999999166
999999821
1999998987
1999999066
2999998384
2999998755
3999997477
3999998367
4999997660
4999997681
5999996868
5999997271
6999996085
6999996152
7999995718
7999996481
8999995529
8999995734
9999994521
9999995274
10999994875
10999995215
11999994235
11999994695
12999993584
12999994319
13999993...

result:

ok 239785 lines

Test #25:

score: 16
Accepted
time: 598ms
memory: 949636kb

input:

421537 1
1 381139 272652694
1 313245 428864113
2 409704 479244149
2 412920 797106836
2 282754 622598996
2 140596 403113561
2 229808 812265100
2 208622 57529918
2 317370 348414517
1 270895 681858627
2 277652 820886845
1 412881 414971866
2 298352 494420124
2 307212 672900847
2 405412 82742555
1 262643...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 421537 lines

Test #26:

score: 16
Accepted
time: 256ms
memory: 945340kb

input:

241804 1
1 120901 999999099
2 120902 999999689
2 120900 999999903
1 120903 999999505
1 120899 999999451
2 120904 999999793
2 120898 999999406
1 120905 999999189
1 120897 999999887
2 120906 999999781
2 120896 999999868
1 120907 999999552
1 120895 999999942
2 120908 999999769
2 120894 999999607
1 1209...

output:

0
999999099
999999099
1999998604
1999999592
2999998055
2999998055
3999997244
3999998791
4999996650
4999997131
5999996683
5999998440
6999996070
6999996625
7999996394
7999997816
8999995656
8999995756
9999994586
9999996059
10999994401
10999994707
11999993054
11999994963
12999993962
12999994170
13999992...

result:

ok 241804 lines

Test #27:

score: 16
Accepted
time: 727ms
memory: 950624kb

input:

500000 1
1 338989 787204560
1 458075 738516495
2 126054 1060970
1 402645 653584288
1 87189 495460187
1 488237 513225755
1 297097 431124895
2 248642 987479559
1 216629 389558190
1 130079 133251494
1 309273 631561475
2 378522 731139370
2 107778 285132222
2 172864 386675893
1 455931 166536939
1 70335 3...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 500000 lines

Test #28:

score: 16
Accepted
time: 514ms
memory: 950908kb

input:

500000 1
1 249999 999999459
2 250000 999999806
2 249998 999999573
1 250001 999999013
1 249997 999999659
2 250002 999999171
2 249996 999999923
1 250003 999999555
1 249995 999999063
2 250004 999999143
2 249994 999999648
1 250005 999999715
1 249993 999999351
2 250006 999999207
2 249992 999999347
1 2500...

output:

0
999999459
999999459
1999998472
1999999379
2999998045
2999998131
3999997302
3999998473
4999996749
4999996749
5999995508
5999997264
6999995815
6999995815
7999994066
7999995818
8999994329
8999994712
9999993759
9999994969
10999993155
10999994102
11999993304
11999994383
12999992571
12999992906
13999991...

result:

ok 500000 lines

Test #29:

score: 16
Accepted
time: 715ms
memory: 949192kb

input:

500000 1
2 443590 175901875
1 75931 53321368
1 344843 535672556
2 4784 499511307
2 107410 763226502
1 411161 817833764
2 315494 427876343
2 405680 460699936
2 52056 119894683
2 362750 777455173
2 54228 968267889
1 297849 871045163
1 385601 638969233
2 321536 391867900
1 413969 932932054
1 4273 79077...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 500000 lines

Test #30:

score: 16
Accepted
time: 531ms
memory: 949568kb

input:

500000 1
1 249999 999999568
2 250000 999999678
2 249998 999999933
1 250001 999999804
1 249997 999999748
2 250002 999999727
2 249996 999999397
1 250003 999999208
1 249995 999999002
2 250004 999999833
2 249994 999999316
1 250005 999999480
1 249993 999999610
2 250006 999999699
2 249992 999999269
1 2500...

output:

0
999999568
999999568
1999999246
1999999611
2999999120
2999999120
3999998328
3999998735
4999997330
4999997330
5999996810
5999997884
6999996126
6999996420
7999995942
7999996852
8999994917
8999995732
9999995167
9999996027
10999993980
10999994432
11999994327
11999995028
12999993066
12999994349
13999993...

result:

ok 500000 lines

Test #31:

score: 16
Accepted
time: 256ms
memory: 944668kb

input:

223052 1
1 111525 999999223
1 111527 999999821
1 111523 999999436
1 111529 999999342
1 111521 999999794
1 111531 999999877
1 111519 999999972
1 111533 999999139
1 111517 999999913
1 111535 999999747
1 111515 999999242
1 111537 999999803
1 111513 999999411
1 111539 999999968
1 111511 999999734
1 1115...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 223052 lines

Test #32:

score: 16
Accepted
time: 324ms
memory: 947644kb

input:

307040 1
1 153519 999999816
1 153521 999999821
1 153517 999999943
1 153523 999999218
1 153515 999999402
1 153525 999999991
1 153513 999999260
1 153527 999999867
1 153511 999999165
1 153529 999999700
1 153509 999999854
1 153531 999999688
1 153507 999999504
1 153533 999999948
1 153505 999999458
1 1535...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 307040 lines

Test #33:

score: 16
Accepted
time: 487ms
memory: 950232kb

input:

500000 1
1 249999 999999399
1 250001 999999082
1 249997 999999317
1 250003 999999550
1 249995 999999659
1 250005 999999075
1 249993 999999961
1 250007 999999206
1 249991 999999781
1 250009 999999582
1 249989 999999650
1 250011 999999913
1 249987 999999491
1 250013 999999977
1 249985 999999353
1 2500...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 500000 lines

Test #34:

score: 16
Accepted
time: 495ms
memory: 949096kb

input:

500000 1
1 249999 999999818
1 250001 999999869
1 249997 999999739
1 250003 999999234
1 249995 999999956
1 250005 999999753
1 249993 999999938
1 250007 999999290
1 249991 999999845
1 250009 999999044
1 249989 999999656
1 250011 999999003
1 249987 999999534
1 250013 999999383
1 249985 999999625
1 2500...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 500000 lines

Subtask #3:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 547ms
memory: 950180kb

input:

401626 1
1 457671 568783758
1 417077 607440922
1 139391 32824188
1 14373 220864694
1 118370 531535298
1 266098 186053453
1 127727 666497333
1 338836 353757976
1 481683 518470240
1 480524 68393518
1 232781 901754468
1 8039 85894025
1 439988 468564731
1 27639 140803132
1 241258 222831725
1 477544 9656...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 200815th lines differ - expected: '99669053', found: '1215520'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%