結果
問題 | No.1705 Mode of long array |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:30:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 237 ms / 3,000 ms |
コード長 | 1,530 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,184 KB |
実行使用メモリ | 132,752 KB |
最終ジャッジ日時 | 2025-03-20 20:31:50 |
合計ジャッジ時間 | 11,821 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
import sys def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 a = list(map(int, input[ptr:ptr+M])) ptr += M Q = int(input[ptr]) ptr += 1 queries = [] for _ in range(Q): T = int(input[ptr]) X = int(input[ptr+1]) Y = int(input[ptr+2]) queries.append((T, X, Y)) ptr += 3 # Determine the size of the segment tree as the next power of two >= M size = 1 while size < M: size *= 2 # Initialize the segment tree tree = [(0, 0)] * (2 * size) for x in range(1, M + 1): tree[size + x - 1] = (a[x - 1], x) for x in range(M + 1, size + 1): tree[size + x - 1] = (0, x) # Build the internal nodes for i in range(size - 1, 0, -1): tree[i] = max(tree[2 * i], tree[2 * i + 1]) output = [] for t, x, y in queries: if t == 1 or t == 2: pos = size + x - 1 current_count, current_x = tree[pos] if t == 1: new_count = current_count + y else: new_count = current_count - y tree[pos] = (new_count, x) pos //= 2 while pos >= 1: left = 2 * pos right = 2 * pos + 1 tree[pos] = max(tree[left], tree[right]) pos //= 2 else: output.append(str(tree[1][1])) print('\n'.join(output)) if __name__ == '__main__': main()