結果
問題 | No.1097 Remainder Operation |
ユーザー | vwxyz |
提出日時 | 2024-07-17 15:16:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 901 ms / 2,000 ms |
コード長 | 2,291 bytes |
コンパイル時間 | 378 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 158,080 KB |
最終ジャッジ日時 | 2024-07-17 15:16:55 |
合計ジャッジ時間 | 11,808 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,736 KB |
testcase_01 | AC | 38 ms
52,992 KB |
testcase_02 | AC | 51 ms
62,720 KB |
testcase_03 | AC | 51 ms
62,720 KB |
testcase_04 | AC | 49 ms
61,696 KB |
testcase_05 | AC | 53 ms
62,976 KB |
testcase_06 | AC | 52 ms
62,976 KB |
testcase_07 | AC | 194 ms
84,200 KB |
testcase_08 | AC | 166 ms
84,312 KB |
testcase_09 | AC | 158 ms
84,244 KB |
testcase_10 | AC | 160 ms
84,224 KB |
testcase_11 | AC | 162 ms
83,792 KB |
testcase_12 | AC | 753 ms
157,880 KB |
testcase_13 | AC | 769 ms
157,584 KB |
testcase_14 | AC | 789 ms
157,440 KB |
testcase_15 | AC | 813 ms
157,440 KB |
testcase_16 | AC | 763 ms
157,532 KB |
testcase_17 | AC | 630 ms
158,080 KB |
testcase_18 | AC | 594 ms
156,160 KB |
testcase_19 | AC | 688 ms
156,464 KB |
testcase_20 | AC | 712 ms
156,152 KB |
testcase_21 | AC | 863 ms
156,348 KB |
testcase_22 | AC | 901 ms
156,144 KB |
ソースコード
class Path_Doubling: def __init__(self,N,permutation,lst=None,f=None,e=None): self.N=N self.permutation=permutation self.lst=lst self.f=f self.e=e def Build_Next(self,K=None): if K==None: K=self.N self.k=K.bit_length() self.permutation_doubling=[[None]*self.N for k in range(self.k)] for n in range(self.N): self.permutation_doubling[0][n]=self.permutation[n] if self.lst!=None: self.doubling=[[self.e]*self.N for k in range(self.k)] for n in range(self.N): self.doubling[0][n]=self.lst[n] for k in range(1,self.k): for n in range(self.N): if self.permutation_doubling[k-1][n]!=None: self.permutation_doubling[k][n]=self.permutation_doubling[k-1][self.permutation_doubling[k-1][n]] if self.f!=None: self.doubling[k][n]=self.f(self.doubling[k-1][n],self.doubling[k-1][self.permutation_doubling[k-1][n]]) def Permutation_Doubling(self,N,K): if K<0 or 1<<self.k<=K: return None for k in range(self.k): if K>>k&1 and N!=None: N=self.permutation_doubling[k][N] return N def Doubling(self,N,K): if K<0: return self.e retu=self.e for k in range(self.k): if K>>k&1: if self.permutation_doubling[k][N]==None: return None retu=self.f(retu,self.doubling[k][N]) N=self.permutation_doubling[k][N] return N,self.f(retu,self.lst[N]) def Bisect(self,x,is_ok): if not is_ok(x): return -1,None K=0 for k in range(self.k-1,-1,-1): if is_ok(self.permutation_doubling[k][x]): K|=1<<k x=self.permutation_doubling[k][x] return K,x N=int(input()) A=list(map(int,input().split())) perm=[None]*N cnt=[None]*N for x in range(N): perm[x]=(x+A[x%N])%N cnt[x]=(x+A[x%N])//N Q=int(input()) PD=Path_Doubling(N,perm,cnt,lambda c0,c1:c0+c1,0) PD.Build_Next(10**12) for q in range(Q): K=int(input()) r,c=PD.Doubling(0,K-1) r=perm[r] ans=r+c*N print(ans)