結果

問題 No.2276 I Want AC
ユーザー chineristACchineristAC
提出日時 2023-04-21 21:27:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 364 ms / 2,000 ms
コード長 1,948 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 142,732 KB
最終ジャッジ日時 2024-04-24 07:37:21
合計ジャッジ時間 13,905 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
68,352 KB
testcase_01 AC 75 ms
68,352 KB
testcase_02 AC 73 ms
68,224 KB
testcase_03 AC 74 ms
68,352 KB
testcase_04 AC 77 ms
68,224 KB
testcase_05 AC 77 ms
68,608 KB
testcase_06 AC 77 ms
68,224 KB
testcase_07 AC 76 ms
68,224 KB
testcase_08 AC 76 ms
68,224 KB
testcase_09 AC 76 ms
68,224 KB
testcase_10 AC 75 ms
68,480 KB
testcase_11 AC 153 ms
92,488 KB
testcase_12 AC 275 ms
132,016 KB
testcase_13 AC 154 ms
92,224 KB
testcase_14 AC 133 ms
84,480 KB
testcase_15 AC 199 ms
106,376 KB
testcase_16 AC 192 ms
106,280 KB
testcase_17 AC 296 ms
133,800 KB
testcase_18 AC 223 ms
111,828 KB
testcase_19 AC 115 ms
80,256 KB
testcase_20 AC 325 ms
139,224 KB
testcase_21 AC 177 ms
103,612 KB
testcase_22 AC 130 ms
88,832 KB
testcase_23 AC 267 ms
134,616 KB
testcase_24 AC 271 ms
134,676 KB
testcase_25 AC 285 ms
134,792 KB
testcase_26 AC 319 ms
139,048 KB
testcase_27 AC 287 ms
137,712 KB
testcase_28 AC 246 ms
131,796 KB
testcase_29 AC 232 ms
128,068 KB
testcase_30 AC 273 ms
137,072 KB
testcase_31 AC 191 ms
121,820 KB
testcase_32 AC 292 ms
138,120 KB
testcase_33 AC 284 ms
137,060 KB
testcase_34 AC 313 ms
141,396 KB
testcase_35 AC 158 ms
114,560 KB
testcase_36 AC 157 ms
114,816 KB
testcase_37 AC 364 ms
142,640 KB
testcase_38 AC 166 ms
114,944 KB
testcase_39 AC 168 ms
114,816 KB
testcase_40 AC 165 ms
114,944 KB
testcase_41 AC 168 ms
114,816 KB
testcase_42 AC 355 ms
142,472 KB
testcase_43 AC 346 ms
142,732 KB
testcase_44 AC 165 ms
113,920 KB
testcase_45 AC 308 ms
139,056 KB
testcase_46 AC 300 ms
138,896 KB
testcase_47 AC 159 ms
113,792 KB
testcase_48 AC 161 ms
113,792 KB
testcase_49 AC 297 ms
139,252 KB
testcase_50 AC 287 ms
138,864 KB
testcase_51 AC 306 ms
138,956 KB
testcase_52 AC 296 ms
139,112 KB
testcase_53 AC 294 ms
138,636 KB
testcase_54 AC 236 ms
130,180 KB
testcase_55 AC 218 ms
124,856 KB
testcase_56 AC 206 ms
121,792 KB
testcase_57 AC 196 ms
121,704 KB
testcase_58 AC 201 ms
122,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

from math import sqrt, ceil
from bisect import bisect_left, bisect_right
from typing import Iterable


input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            k >>= 1
            self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1])

    def query(self, l, r):
        if r==self.size:
            r = self.num

        res = self.ide_ele

        l += self.num
        r += self.num
        right = []
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                right.append(self.tree[r-1])
            l >>= 1
            r >>= 1

        for e in right[::-1]:
            res = self.segfunc(res,e)
        return res

def merge(x,y):
    return (x[0]+y[0],x[1]+y[1],x[2]+y[2]+x[0]*y[1])

N = int(input())
S = [s for s in input()]

idx = [i for i in range(N) if S[i]=="?"]
init = [-1] * N
for i in range(N):
    if S[i]=="A":
        init[i] = (1,0,0)
    else:
        init[i] = (0,1,0)
seg = SegmentTree(init,merge,(0,0,0))

res = seg.tree[1][2]
for i in idx:
    seg.update(i,(1,0,0))
    res = max(res,seg.tree[1][2])
print(res)

0