結果
問題 | No.2281 K → K-1 01 Flip |
ユーザー | miscalc |
提出日時 | 2023-04-21 11:43:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 873 ms / 2,000 ms |
コード長 | 3,479 bytes |
コンパイル時間 | 267 ms |
コンパイル使用メモリ | 82,848 KB |
実行使用メモリ | 99,752 KB |
最終ジャッジ日時 | 2024-11-06 07:58:06 |
合計ジャッジ時間 | 36,769 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,736 KB |
testcase_01 | AC | 280 ms
89,112 KB |
testcase_02 | AC | 795 ms
86,816 KB |
testcase_03 | AC | 816 ms
96,608 KB |
testcase_04 | AC | 356 ms
80,440 KB |
testcase_05 | AC | 467 ms
89,248 KB |
testcase_06 | AC | 679 ms
86,940 KB |
testcase_07 | AC | 330 ms
96,320 KB |
testcase_08 | AC | 560 ms
96,908 KB |
testcase_09 | AC | 760 ms
80,956 KB |
testcase_10 | AC | 653 ms
81,652 KB |
testcase_11 | AC | 381 ms
83,184 KB |
testcase_12 | AC | 341 ms
94,580 KB |
testcase_13 | AC | 742 ms
82,012 KB |
testcase_14 | AC | 500 ms
89,092 KB |
testcase_15 | AC | 365 ms
79,596 KB |
testcase_16 | AC | 760 ms
87,096 KB |
testcase_17 | AC | 832 ms
89,420 KB |
testcase_18 | AC | 807 ms
84,380 KB |
testcase_19 | AC | 464 ms
94,492 KB |
testcase_20 | AC | 378 ms
80,512 KB |
testcase_21 | AC | 345 ms
82,704 KB |
testcase_22 | AC | 686 ms
80,424 KB |
testcase_23 | AC | 196 ms
78,108 KB |
testcase_24 | AC | 500 ms
78,760 KB |
testcase_25 | AC | 384 ms
78,172 KB |
testcase_26 | AC | 367 ms
87,616 KB |
testcase_27 | AC | 557 ms
96,488 KB |
testcase_28 | AC | 349 ms
94,584 KB |
testcase_29 | AC | 146 ms
77,924 KB |
testcase_30 | AC | 538 ms
78,572 KB |
testcase_31 | AC | 499 ms
82,052 KB |
testcase_32 | AC | 630 ms
87,620 KB |
testcase_33 | AC | 465 ms
86,688 KB |
testcase_34 | AC | 555 ms
78,576 KB |
testcase_35 | AC | 498 ms
92,948 KB |
testcase_36 | AC | 687 ms
78,468 KB |
testcase_37 | AC | 667 ms
85,280 KB |
testcase_38 | AC | 648 ms
78,400 KB |
testcase_39 | AC | 405 ms
79,076 KB |
testcase_40 | AC | 254 ms
86,908 KB |
testcase_41 | AC | 794 ms
90,140 KB |
testcase_42 | AC | 811 ms
93,048 KB |
testcase_43 | AC | 804 ms
90,416 KB |
testcase_44 | AC | 860 ms
99,564 KB |
testcase_45 | AC | 815 ms
93,416 KB |
testcase_46 | AC | 676 ms
81,636 KB |
testcase_47 | AC | 775 ms
89,912 KB |
testcase_48 | AC | 765 ms
87,796 KB |
testcase_49 | AC | 873 ms
99,752 KB |
testcase_50 | AC | 748 ms
86,576 KB |
testcase_51 | AC | 589 ms
79,956 KB |
testcase_52 | AC | 577 ms
80,016 KB |
testcase_53 | AC | 564 ms
79,960 KB |
testcase_54 | AC | 572 ms
79,728 KB |
testcase_55 | AC | 568 ms
80,072 KB |
testcase_56 | AC | 576 ms
80,236 KB |
ソースコード
# https://github.com/shakayami/ACL-for-python/blob/master/segtree.py class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] for i in range(self.n): self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1): self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size self.d[p]=x for i in range(1,self.log+1): self.update(p>>i) def get(self,p): assert 0<=p and p<self.n return self.d[p+self.size] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n sml=self.e smr=self.e l+=self.size r+=self.size while(l<r): if (l&1): sml=self.op(sml,self.d[l]) l+=1 if (r&1): smr=self.op(self.d[r-1],smr) r-=1 l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def max_right(self,l,f): assert 0<=l and l<=self.n assert f(self.e) if l==self.n: return self.n l+=self.size sm=self.e while(1): while(l%2==0): l>>=1 if not(f(self.op(sm,self.d[l]))): while(l<self.size): l=2*l if f(self.op(sm,self.d[l])): sm=self.op(sm,self.d[l]) l+=1 return l-self.size sm=self.op(sm,self.d[l]) l+=1 if (l&-l)==l: break return self.n def min_left(self,r,f): assert 0<=r and r<=self.n assert f(self.e) if r==0: return 0 r+=self.size sm=self.e while(1): r-=1 while(r>1 and (r%2)): r>>=1 if not(f(self.op(self.d[r],sm))): while(r<self.size): r=(2*r+1) if f(self.op(self.d[r],sm)): sm=self.op(self.d[r],sm) r-=1 return r+1-self.size sm=self.op(self.d[r],sm) if (r& -r)==r: break return 0 def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) n, q = map(int, input().split()) s = input() cum = [0] * (n + 1) for i in range(n): cum[i + 1] = cum[i] + (1 if s[i] == '0' else -1) left, right, length = list(), list(), list() where = [0] * n for i in range(n): if i != 0 and s[i - 1] == s[i]: right[-1] += 1 length[-1] += 1 else: left.append(i) right.append(i) length.append(1) where[i] = len(left) - 1 seg = segtree(length, max, -10**9) for _ in range(q): l, r, k = map(int, input().split()) l -= 1 r -= 1 li, ri = where[l], where[r] ok = False if right[li] - l + 1 >= k: ok = True elif r - left[ri] + 1 >= k: ok = True else: li += 1 ri -= 1 if li <= ri and seg.prod(li, ri + 1) >= k: ok = True if (not ok): print(r - l + 1) continue x = (cum[r + 1] - cum[l]) % (2*k - 1) print(max(x - 1, 2*k - 2 - x))