結果
問題 | No.752 mod数列 |
ユーザー | vwxyz |
提出日時 | 2022-09-22 15:13:56 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,117 ms / 2,000 ms |
コード長 | 2,938 bytes |
コンパイル時間 | 84 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 22,380 KB |
最終ジャッジ日時 | 2024-06-01 17:55:28 |
合計ジャッジ時間 | 17,068 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 96 ms
21,400 KB |
testcase_01 | AC | 98 ms
21,408 KB |
testcase_02 | AC | 93 ms
21,220 KB |
testcase_03 | AC | 94 ms
21,192 KB |
testcase_04 | AC | 88 ms
17,612 KB |
testcase_05 | AC | 96 ms
21,404 KB |
testcase_06 | AC | 95 ms
21,436 KB |
testcase_07 | AC | 96 ms
21,404 KB |
testcase_08 | AC | 91 ms
21,288 KB |
testcase_09 | AC | 94 ms
21,252 KB |
testcase_10 | AC | 113 ms
21,744 KB |
testcase_11 | AC | 108 ms
21,492 KB |
testcase_12 | AC | 109 ms
21,736 KB |
testcase_13 | AC | 108 ms
21,356 KB |
testcase_14 | AC | 112 ms
21,872 KB |
testcase_15 | AC | 447 ms
20,620 KB |
testcase_16 | AC | 501 ms
22,128 KB |
testcase_17 | AC | 879 ms
22,380 KB |
testcase_18 | AC | 547 ms
21,320 KB |
testcase_19 | AC | 679 ms
21,440 KB |
testcase_20 | AC | 898 ms
21,260 KB |
testcase_21 | AC | 902 ms
21,452 KB |
testcase_22 | AC | 859 ms
21,432 KB |
testcase_23 | AC | 902 ms
21,488 KB |
testcase_24 | AC | 852 ms
21,480 KB |
testcase_25 | AC | 411 ms
21,996 KB |
testcase_26 | AC | 810 ms
21,872 KB |
testcase_27 | AC | 595 ms
21,744 KB |
testcase_28 | AC | 746 ms
21,996 KB |
testcase_29 | AC | 789 ms
21,616 KB |
testcase_30 | AC | 1,117 ms
21,492 KB |
testcase_31 | AC | 87 ms
16,560 KB |
testcase_32 | AC | 85 ms
16,816 KB |
testcase_33 | AC | 100 ms
21,740 KB |
ソースコード
import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys import time from collections import Counter,deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] = heap[0], item heapq._siftup_max(heap, 0) return item from math import gcd as GCD read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines write=sys.stdout.write class Cumsum: def __init__(self,lst,mod=0): self.N=len(lst) self.mod=mod self.cumsum=[0]*(self.N+1) self.cumsum[0]=0 for i in range(1,self.N+1): self.cumsum[i]=self.cumsum[i-1]+lst[i-1] if self.mod: self.cumsum[i]%=self.mod def __getitem__(self,i): if type(i)==int: if 0<=i<self.N: a,b=i,i+1 elif -self.N<=i<0: a,b=i+self.N,i+self.N+1 else: raise IndexError('list index out of range') else: a,b=i.start,i.stop if a==None or a<-self.N: a=0 elif self.N<=a: a=self.N elif a<0: a+=self.N if b==None or self.N<=b: b=self.N elif b<-self.N: b=0 elif b<0: b+=self.N s=self.cumsum[b]-self.cumsum[a] if self.mod: s%=self.mod return s def __setitem__(self,i,x): if -self.N<=i<0: i+=self.N elif not 0<=i<self.N: raise IndexError('list index out of range') self.cumsum[i+1]=self.cumsum[i]+x if self.mod: self.cumsum[i+1]%=self.mod def __str__(self): lst=[self.cumsum[i+1]-self.cumsum[i] for i in range(self.N)] if self.mod: for i in range(self.N): lst[i]%=self.mod return "["+", ".join(map(str,lst))+"]" def Bisect_Int(ok,ng,is_ok): while abs(ok-ng)>1: mid=(ok+ng)//2 if is_ok(mid): ok=mid else: ng=mid return ok P,Q=map(int,readline().split()) M=10**5 A=[0]+[P//n for n in range(1,M)] PP=A[-1]+1 for i in range(1,M): A[i]*=i bound=[10**9+1]+[P//n+1 for n in range(1,PP+1)] B=[(bound[i]-bound[i+1])*(bound[i]+bound[i+1]-1)//2*i for i in range(PP)] A=Cumsum(A) B=Cumsum(B) def S(c): if c<=M: return A[:c] def is_ok(x): return c>=bound[x] x=Bisect_Int(PP,-1,is_ok) return A[:bound[PP]]+B[x:]+(x-1)*(c-bound[x])*(bound[x]+c-1)//2 for q in range(Q): L,R=map(int,readline().split()) R+=1 ans=P*(R-L)-(S(R)-S(L)) print(ans)