結果

問題 No.2716 Falcon Method
ユーザー rlangevinrlangevin
提出日時 2024-04-07 01:20:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,613 ms / 2,000 ms
コード長 1,964 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 102,312 KB
最終ジャッジ日時 2024-04-07 01:20:27
合計ジャッジ時間 24,456 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 73 ms
75,504 KB
testcase_07 AC 77 ms
75,504 KB
testcase_08 AC 81 ms
75,556 KB
testcase_09 AC 82 ms
75,520 KB
testcase_10 AC 72 ms
75,504 KB
testcase_11 AC 1,429 ms
100,408 KB
testcase_12 AC 1,134 ms
99,400 KB
testcase_13 AC 946 ms
97,540 KB
testcase_14 AC 1,295 ms
96,908 KB
testcase_15 AC 1,001 ms
96,876 KB
testcase_16 AC 1,114 ms
95,860 KB
testcase_17 AC 1,276 ms
97,608 KB
testcase_18 AC 1,468 ms
99,864 KB
testcase_19 AC 1,114 ms
95,648 KB
testcase_20 AC 916 ms
96,984 KB
testcase_21 AC 1,183 ms
96,752 KB
testcase_22 AC 1,570 ms
102,064 KB
testcase_23 AC 1,592 ms
102,280 KB
testcase_24 AC 1,579 ms
102,312 KB
testcase_25 AC 46 ms
53,460 KB
testcase_26 AC 36 ms
53,460 KB
testcase_27 AC 1,593 ms
102,100 KB
testcase_28 AC 1,613 ms
102,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n

    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def get(self, k):
        k += 1
        x, r = 0, 1
        while r < self._n:
            r <<= 1
        len = r
        while len:
            if x + len - 1 < self._n:
                if self.data[x + len - 1] < k:
                    k -= self.data[x + len - 1]
                    x += len
            len >>= 1
        return x

    def __str__(self):
        temp = []
        for i in range(self._n):
            temp.append(str(self.sum(i, i + 1)))
        return ' '.join(temp)


N, Q = map(int, input().split())
S = list(input())
h = S.count("D")
w = N - h
T1 = Fenwick_Tree(3 * N)
T2 = Fenwick_Tree(3 * N)
for i in range(N):
    if S[i] == "D":
        T1.add(i, 1)
        T1.add(i + N, 1)
        T1.add(i + 2 * N, 1)
    else:
        T2.add(i, 1)
        T2.add(i + N, 1)
        T2.add(i + 2 * N, 1)
        
def BinarySearch(check, yes = 10 ** 18, no = -1):
    while abs(yes - no) != 1:
        mid = (yes + no)//2
        if check(mid):
            yes = mid
        else:
            no = mid
    return yes

def check1(m):
    return (H - h * m) > 0 and (W - w * m) > 0

def check2(r):
    x = T1.sum(P, r)
    y = T2.sum(P, r)
    return H - x <= 0 or W - y <= 0

for _ in range(Q):
    H, W, P = map(int, input().split())
    m = BinarySearch(check1, 0, 10 ** 9 + 5)
    H -= m * h
    W -= m * w
    if H == 0 or W == 0:
        print(P)
        continue
    print(BinarySearch(check2, 3 * N, P)%N)
0