結果

問題 No.1222 -101
ユーザー mkawa2mkawa2
提出日時 2023-06-14 22:14:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 1,565 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 85,904 KB
最終ジャッジ日時 2023-09-05 07:40:07
合計ジャッジ時間 8,214 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
78,984 KB
testcase_01 AC 85 ms
79,192 KB
testcase_02 AC 83 ms
79,296 KB
testcase_03 AC 85 ms
79,292 KB
testcase_04 AC 87 ms
78,976 KB
testcase_05 AC 84 ms
78,968 KB
testcase_06 AC 83 ms
79,040 KB
testcase_07 AC 84 ms
78,916 KB
testcase_08 AC 84 ms
79,116 KB
testcase_09 AC 83 ms
79,156 KB
testcase_10 AC 109 ms
84,164 KB
testcase_11 AC 100 ms
84,016 KB
testcase_12 AC 208 ms
85,540 KB
testcase_13 AC 211 ms
85,396 KB
testcase_14 AC 208 ms
85,284 KB
testcase_15 AC 168 ms
85,300 KB
testcase_16 AC 188 ms
85,300 KB
testcase_17 AC 205 ms
85,404 KB
testcase_18 AC 163 ms
85,424 KB
testcase_19 AC 180 ms
85,472 KB
testcase_20 AC 197 ms
85,340 KB
testcase_21 AC 195 ms
85,420 KB
testcase_22 AC 86 ms
79,208 KB
testcase_23 AC 88 ms
79,088 KB
testcase_24 AC 88 ms
78,952 KB
testcase_25 AC 90 ms
78,972 KB
testcase_26 AC 87 ms
79,100 KB
testcase_27 AC 86 ms
79,264 KB
testcase_28 AC 84 ms
79,012 KB
testcase_29 AC 86 ms
78,984 KB
testcase_30 AC 84 ms
79,168 KB
testcase_31 AC 87 ms
79,204 KB
testcase_32 AC 205 ms
85,532 KB
testcase_33 AC 197 ms
85,544 KB
testcase_34 AC 198 ms
84,960 KB
testcase_35 AC 199 ms
85,136 KB
testcase_36 AC 201 ms
85,424 KB
testcase_37 AC 202 ms
85,904 KB
testcase_38 AC 202 ms
85,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(1000005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
md = 10**9+7
# md = 998244353

mx = 200005
pw = [1]*mx
ipw = [1]*mx
for i in range(mx-1): pw[i+1] = pw[i]*2%md
ipw[-1] = pow(pw[-1], md-2, md)
for i in range(mx-1)[::-1]: ipw[i] = ipw[i+1]*2%md

n, m = LI()
rtol = [-1]*(n+1)
ng = [0]*(n+2)
c = 0
mxl = -1
for _ in range(m):
    l, r, p = LI()
    if p:
        c += 1
        ng[l] += 1
        ng[r+1] -= 1
    else:
        rtol[r] = l
        mxl = max(mxl, l)
for i in range(n+1): ng[i+1] += ng[i]

# dpi=sum(dpj*2^(i-j-1))
# dpi=2^(i-1)*sum(dpj*2^(-j))
cs = [0]*(n+2)
cs[1] = 1

l = 0
ans = 0
if mxl == -1: ans = pw[n]
for i in range(1, n+1):
    cs[i+1] = cs[i]
    if ng[i]==0:
        v = pw[i-1]*(cs[i]-cs[l])%md
        if i >= mxl:
            ans += v*pw[n-i]%md
            ans %= md
        cs[i+1] += v*ipw[i]%md
        cs[i+1] %= md
    l = max(l, rtol[i])

ans *= ipw[c]
print(ans%md)
0