結果

問題 No.1386 Range add Simulation
ユーザー MitarushiMitarushi
提出日時 2021-02-07 18:27:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 86,688 KB
実行使用メモリ 129,508 KB
最終ジャッジ日時 2023-09-17 18:49:36
合計ジャッジ時間 32,868 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,164 KB
testcase_01 AC 128 ms
78,888 KB
testcase_02 AC 125 ms
78,384 KB
testcase_03 AC 142 ms
78,788 KB
testcase_04 AC 128 ms
78,452 KB
testcase_05 AC 139 ms
79,332 KB
testcase_06 AC 318 ms
105,272 KB
testcase_07 AC 296 ms
104,304 KB
testcase_08 AC 304 ms
104,656 KB
testcase_09 AC 291 ms
104,672 KB
testcase_10 AC 298 ms
105,668 KB
testcase_11 AC 440 ms
125,308 KB
testcase_12 AC 452 ms
128,268 KB
testcase_13 AC 429 ms
123,636 KB
testcase_14 AC 424 ms
123,864 KB
testcase_15 AC 440 ms
127,864 KB
testcase_16 AC 443 ms
128,092 KB
testcase_17 AC 433 ms
127,932 KB
testcase_18 AC 426 ms
125,300 KB
testcase_19 AC 425 ms
125,296 KB
testcase_20 AC 452 ms
125,572 KB
testcase_21 AC 436 ms
124,820 KB
testcase_22 AC 443 ms
129,316 KB
testcase_23 AC 433 ms
125,496 KB
testcase_24 AC 449 ms
128,172 KB
testcase_25 AC 442 ms
128,112 KB
testcase_26 AC 437 ms
127,188 KB
testcase_27 AC 444 ms
129,508 KB
testcase_28 AC 425 ms
127,572 KB
testcase_29 AC 426 ms
125,184 KB
testcase_30 AC 423 ms
123,944 KB
testcase_31 AC 398 ms
120,396 KB
testcase_32 AC 398 ms
120,480 KB
testcase_33 AC 392 ms
120,680 KB
testcase_34 AC 383 ms
120,716 KB
testcase_35 AC 75 ms
71,172 KB
testcase_36 AC 152 ms
77,740 KB
testcase_37 AC 130 ms
77,336 KB
testcase_38 AC 158 ms
77,724 KB
testcase_39 AC 151 ms
77,812 KB
testcase_40 AC 425 ms
127,832 KB
testcase_41 AC 415 ms
125,736 KB
testcase_42 AC 417 ms
127,564 KB
testcase_43 AC 414 ms
126,404 KB
testcase_44 AC 434 ms
126,512 KB
testcase_45 AC 427 ms
127,412 KB
testcase_46 AC 417 ms
125,868 KB
testcase_47 AC 429 ms
127,672 KB
testcase_48 AC 417 ms
127,416 KB
testcase_49 AC 430 ms
125,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, q = map(int, input().split())

print_cache = []


def print_c(*args):
    print_cache.append(args)


def flush():
    print(len(print_cache))
    for args in print_cache:
        print(*args)


def doubling(x, i):
    flag = False
    t = True
    if x < 0:
        x = abs(x)
        t = False
    for j in range(x.bit_length())[::-1]:
        if flag:
            print_c(3, i+1, i+1)
        else:
            flag = True
        if (x >> j) & 1 == 1:
            if t:
                print_c(1, i+1)
            else:
                print_c(2, i+1)


if n <= 10000:
    a = [0] * n
    for _ in range(q):
        c, s = map(int, input().split())
        s -= 1
        if c == 1:
            for j in range(s, n):
                a[j] += (j-s+1)**2
        else:
            for j in range(s+1):
                a[j] += (s-j+1)**2
    for i in range(n):
        doubling(a[i], i)
else:
    a = [0] * n
    b = [0] * 5
    for _ in range(q):
        c, s = map(int, input().split())
        s -= 1
        if c == 1:
            a[s] += 1
            if s+1 < n:
                a[s+1] += 1

            for i in range(5):
                if s <= i:
                    b[i] += (i-s+1)**2
        else:
            if s+2 < n:
                a[s+2] -= 1
            if s+3 < n:
                a[s+3] -= 1

            for i in range(5):
                if i <= s:
                    b[i] += (s-i+1)**2

    for i in range(3):
        for j in range(i+1, 5)[::-1]:
            b[j] -= b[j-1]

    for i in range(5):
        doubling(b[i], i)
    for i in range(5, n):
        doubling(a[i], i)

    for i in range(3)[::-1]:
        for j in range(i+1, n):
            print_c(3, j+1, j)

flush()
0