結果

問題 No.2170 Left Addition Machine
ユーザー mkawa2mkawa2
提出日時 2022-12-24 10:09:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 1,516 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 87,352 KB
実行使用メモリ 145,288 KB
最終ジャッジ日時 2023-08-11 13:50:07
合計ジャッジ時間 31,245 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,592 KB
testcase_01 AC 76 ms
71,352 KB
testcase_02 AC 75 ms
71,268 KB
testcase_03 AC 407 ms
135,792 KB
testcase_04 AC 208 ms
78,812 KB
testcase_05 AC 271 ms
92,064 KB
testcase_06 AC 280 ms
100,716 KB
testcase_07 AC 359 ms
101,184 KB
testcase_08 AC 156 ms
91,380 KB
testcase_09 AC 308 ms
86,320 KB
testcase_10 AC 148 ms
78,444 KB
testcase_11 AC 238 ms
96,808 KB
testcase_12 AC 426 ms
137,472 KB
testcase_13 AC 427 ms
137,488 KB
testcase_14 AC 425 ms
137,536 KB
testcase_15 AC 422 ms
137,248 KB
testcase_16 AC 419 ms
137,512 KB
testcase_17 AC 423 ms
137,608 KB
testcase_18 AC 418 ms
137,356 KB
testcase_19 AC 420 ms
137,240 KB
testcase_20 AC 423 ms
137,664 KB
testcase_21 AC 268 ms
79,456 KB
testcase_22 AC 267 ms
79,780 KB
testcase_23 AC 267 ms
80,196 KB
testcase_24 AC 270 ms
80,420 KB
testcase_25 AC 272 ms
79,748 KB
testcase_26 AC 272 ms
80,000 KB
testcase_27 AC 270 ms
79,728 KB
testcase_28 AC 272 ms
79,628 KB
testcase_29 AC 272 ms
80,152 KB
testcase_30 AC 355 ms
131,276 KB
testcase_31 AC 352 ms
131,088 KB
testcase_32 AC 348 ms
131,272 KB
testcase_33 AC 349 ms
131,056 KB
testcase_34 AC 350 ms
130,856 KB
testcase_35 AC 357 ms
130,964 KB
testcase_36 AC 356 ms
131,284 KB
testcase_37 AC 354 ms
131,160 KB
testcase_38 AC 354 ms
131,128 KB
testcase_39 AC 226 ms
78,804 KB
testcase_40 AC 227 ms
78,552 KB
testcase_41 AC 226 ms
78,680 KB
testcase_42 AC 224 ms
78,544 KB
testcase_43 AC 233 ms
78,652 KB
testcase_44 AC 227 ms
78,696 KB
testcase_45 AC 227 ms
78,676 KB
testcase_46 AC 224 ms
78,616 KB
testcase_47 AC 225 ms
78,728 KB
testcase_48 AC 367 ms
130,244 KB
testcase_49 AC 368 ms
130,040 KB
testcase_50 AC 368 ms
131,064 KB
testcase_51 AC 363 ms
131,280 KB
testcase_52 AC 365 ms
131,232 KB
testcase_53 AC 380 ms
130,204 KB
testcase_54 AC 367 ms
131,088 KB
testcase_55 AC 361 ms
131,088 KB
testcase_56 AC 366 ms
131,316 KB
testcase_57 AC 438 ms
144,552 KB
testcase_58 AC 435 ms
144,564 KB
testcase_59 AC 433 ms
145,000 KB
testcase_60 AC 432 ms
144,936 KB
testcase_61 AC 437 ms
144,856 KB
testcase_62 AC 434 ms
144,560 KB
testcase_63 AC 435 ms
144,604 KB
testcase_64 AC 441 ms
144,536 KB
testcase_65 AC 438 ms
144,788 KB
testcase_66 AC 142 ms
77,624 KB
testcase_67 AC 393 ms
120,228 KB
testcase_68 AC 441 ms
145,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
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
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

class RollingHash:
    def __init__(self, target):
        self.BASE = 2
        self.MOD = md
        self.N = len(target)
        self.table = [0]
        self.power = [1]
        for c in target:
            self.table += [self._mod(self.table[-1]*self.BASE)+c]
            self.power += [self._mod(self.power[-1]*self.BASE)]

    def _mod(self, a):
        return a%self.MOD

    def hash_lr(self, l, r):
        return self._mod(self.table[r]-self._mod(self.table[l]*self.power[r-l]))

from bisect import bisect_left

n, q = LI()
aa = LI()

ii = [0]
for i in range(n-1):
    if aa[i] >= aa[i+1]: ii.append(i+1)

rh = RollingHash(aa[::-1])

for _ in range(q):
    l, r = LI()
    l -= 1
    l = max(l, ii[bisect_left(ii, r)-1])
    ans = rh.hash_lr(n-r, n-(l+1))+aa[l]
    print(ans%md)
0