Problem:


Score : 600 points

Problem Statement

We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}.

Process the following q queries in order:

The i-th query contains three integers n_i, x_i, and m_i.
Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j =  \begin{cases}    x_i & ( j = 0 ) \\    a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 )  \end{cases}\end{eqnarray}
Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i).

Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).

Constraints

All values in input are integers.

1 \leq k, q \leq 5000

0 \leq d_i \leq 10^9

2 \leq n_i \leq 10^9

0 \leq x_i \leq 10^9

2 \leq m_i \leq 10^9

Input

Input is given from Standard Input in the following format:

k q
d_0 d_1 ... d_{k - 1}
n_1 x_1 m_1
n_2 x_2 m_2
:
n_q x_q m_q

Output

Print q lines.

The i-th line should contain the response to the i-th query.

Sample Input 1

3 1
3 1 4
5 3 2

Sample Output 1

1

For the first query, the sequence {a_j} will be 3,6,7,11,14.

(a_0~\textrm{mod}~2) > (a_1~\textrm{mod}~2)

(a_1~\textrm{mod}~2) < (a_2~\textrm{mod}~2)

(a_2~\textrm{mod}~2) = (a_3~\textrm{mod}~2)

(a_3~\textrm{mod}~2) > (a_4~\textrm{mod}~2)

Thus, the response to this query should be 1.

Sample Input 2

7 3
27 18 28 18 28 46 1000000000
1000000000 1 7
1000000000 2 10
1000000000 3 12

Sample Output 2

224489796
214285714
559523809



Sample input:
3 1
3 1 4
5 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:

from itertools import accumulate
def resolve():
    K, Q = map(int, input().split())
    D = list(map(int, input().split()))

    for _ in range(Q):
        n, x, m = map(int, input().split())
        # 最初にmの余りをとっても変わらない
        # 与えられた要素をすべてmod mにとりあえずする
        E = [d%m for d in D]
        acc_E = list(accumulate(E))

        # 数列がN項であるということは、末項は数列dをN-1回足したものである
        loop, rem = divmod(n - 1, K)
        tot = x % m + acc_E[-1] * loop

        # Bi = Bi+1 になっている個所：0の個数
        zero = [int(e == 0) for e in E]
        zero_acc = list(accumulate(zero))
        tot_zero = zero_acc[-1] * loop

        if rem > 0:
            tot += acc_E[rem-1]
            tot_zero += zero_acc[rem - 1]
            dame = tot // m
        print(n - 1 - dame - tot_zero)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


k,q = map(int, input().split())
d = list(map(int, input().split()))

def sub(n,x,m):
    X = 0
    init = x%m
    x%=m
    if n<=k:
        for i in range(n-1):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        ans = X
    else:
        for i in range(k):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        diff = (x-init)
        ans = ((n-1)//k) * X - (init + (diff*((n-1)//k))) // m
        nn = n-((n-1)//k)*k
        xx = (init + (diff*(n//k))) % m
#         if xx<init:
#             ans -= 1
        for i in range(nn-1):
            if xx<(xx+d[i])%m:
                ans += 1
            xx = (xx+d[i])%m
    return ans
#         else:
#             ans = (n//k) * X + (init + (diff*(n//k)))
ans = [None]*q
for i in range(q):
    n,x,m = map(int, input().split())
    ans[i] = sub(n,x,m)
write("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


k,q = map(int, input().split())
d = list(map(int, input().split()))

def sub(n,x,m):
    X = 0
    init = x%m
    x%=m
    if n<=k:
        for i in range(n-1):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        ans = X
    else:
        for i in range(k):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        diff = (x-init)
        ans = (n//k) * X - (init + (diff*(n//k))) // m
        nn = n-(n//k)*k
        xx = (init + (diff*(n//k))) % m
#         if xx<init:
#             ans -= 1
        for i in range(nn-1):
            if xx<(xx+d[i])%m:
                ans += 1
            xx = (xx+d[i])%m
    return ans
#         else:
#             ans = (n//k) * X + (init + (diff*(n//k)))
ans = [None]*q
for i in range(q):
    n,x,m = map(int, input().split())
    ans[i] = sub(n,x,m)
write("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


k,q = map(int, input().split())
d = list(map(int, input().split()))

def sub(n,x,m):
    X = 0
    init = x%m
    x%=m
    if n<k:
        for i in range(n-1):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        ans = X
    else:
        for i in range(k):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        diff = (x-init)
        ans = (n//k) * X - (init + (diff*(n//k))) // m - ((init + (diff*(n//k))) % m == 0)
        nn = n-(n//k)*k
        xx = (init + (diff*(n//k))) % m
        for i in range(nn-1):
            if xx<(xx+d[i])%m:
                ans += 1
            xx = (xx+d[i])%m
    return ans
#         else:
#             ans = (n//k) * X + (init + (diff*(n//k)))
ans = [None]*q
for i in range(q):
    n,x,m = map(int, input().split())
    ans[i] = sub(n,x,m)
write("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



k,q = map(int, input().split())
d = list(map(int, input().split()))

def sub(n,x,m):
    X = 0
    init = x%m
    x%=m
    if n<k:
        for i in range(n-1):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        ans = X
    else:
        for i in range(k):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        diff = (x-init)
        sign = 1 if diff<0 else -1
        ans = (n//k) * X - (init + (diff*(n//k))) // m
        nn = n-(n//k)*k
        xx = (init + (diff*(n//k))) % m
        for i in range(nn-1):
            if xx<(xx+d[i])%m:
                ans += 1
            xx = (xx+d[i])%m
    return ans
#         else:
#             ans = (n//k) * X + (init + (diff*(n//k)))
ans = [None]*q
for i in range(q):
    n,x,m = map(int, input().split())
    ans[i] = sub(n,x,m)
write("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
k, q = map(int, input().split())
d = list(map(int, input().split()))
for _ in range(q):
    n, x, m = map(int, input().split())
    a = list(map(lambda y: y % m, d))
    c = 0
    s = 0
    c2 = 0
    s2 = 0
    for x in a:
        if x == 0:
            c += 1
        s += x
    for x in a[:(n - 1) % k]:
        if x == 0:
            c2 += 1
        s2 += x
    t = s * ((n - 1) // k) + s2 + x % m
    ans = n - 1 - t // m - c * ((n - 1) // k) - c2
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

k,q=map(int,readline().split())
D=np.array(readline().split(),dtype=np.int64)
NXM = map(int, read().split())

NXM=iter(NXM)
NXM=zip(NXM,NXM,NXM)

for n,x,m in NXM:
    tmpD=D%m
    SD=np.array([0]+tmpD,dtype=np.int64)
    SD=np.cumsum(SD)
    n-=1
    x=x%m
    x+=SD[-1]*(n//k)
    x+=SD[n%k]
    count=(k-np.count_nonzero(tmpD))*(n//k)
    count+=n%k-np.count_nonzero(tmpD[:n%k])
    ans=n-x//m-count
    print(ans)

Submission status: Wrong Answer

Solution code:
k,q=map(int,input().split())
D=list(map(int,input().split()))
NXM = map(int, open(0).read().split())

NXM=iter(NXM)
NXM=zip(NXM,NXM,NXM)

for n,x,m in NXM:
    tmpD=list(map(lambda x:x%m,D))
    SD=[0]+tmpD
    n-=1
    for i in range(1,k):
        SD[i+1]+=SD[i]
    x=x%m
    x+=SD[-1]*(n//k)
    x+=SD[n%k]
    count=tmpD.count(0)*(n//k)
    count+=tmpD[:n%k].count(0)
    ans=n-x//m-count
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    k, q = map(int, input().split())
    d = list(map(int, input().split()))

    for qi in range(q):
        n, x, m = map(int, input().split())
        last = x
        eq = 0
        for i in range(k):
            num = math.ceil(n/k)
            if i+1 >= n % k:
                num -= 1  # numはd_iが足される回数
            last += (d[i] % m)*num
            if d[i] % m == 0:
                eq += num

        ans = (n-1)-(last//m-x//m)-eq
        print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations
import numpy as np
def run():
    k,q = map(int, sysread().split())
    d = list(map(int,sysread().split()))
    d = np.array(d, dtype=np.uint32)

    def check(n ,x, m):
        _d = d % m
        d0 = d % m == 0
        # n_step
        n_d = (n-1) // k
        n_rest = (n-1) % k
        x %= m
        _d_rest, d0_rest = 0, 0
        if n_rest != 0:
            _d_rest = _d[:n_rest].sum()
            d0_rest = d0[:n_rest].sum()

        a_last = x + n_d * _d.sum() + _d_rest
        n_step = a_last // m
        # n_same
        n_same = n_d * d0.sum() + d0_rest

        return n-1 - n_same - n_step


    for _ in range(q):
        n,x,m = map(int, sysread().split())
        print(check(n, x, m))

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations
def run():
    k,q = map(int, sysread().split())
    d = list(map(int,sysread().split()))


    def check(n ,x, m):
        _d = [d[0] % m]
        for val in d[1:]:
            _d.append(_d[-1] + val % m)

        # n_step
        n_d = (n-1)// k
        n_rest = (n-1) % k
        x %= m
        _d_rest = 0 if n_rest == 0 else _d[n_rest-1]
        a_last = x + n_d * _d[k-1] + _d_rest
        n_step = a_last // m - x // m
        # n_same
        d0 = [1] if val == 0 else [0]
        for val in d[1:]:
            plus = 1 if val % m == 0 else 0
            d0.append(d0[-1] + plus)
        d0_rest = 0 if n_rest == 0 else d0[n_rest-1]
        n_same = n_d * d0[k-1] + d0_rest

        return n-1 - n_same - n_step


    for _ in range(q):
        n,x,m = map(int, sysread().split())
        print(check(n, x, m))

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations
def run():
    k,q = map(int, sysread().split())
    d = list(map(int,sysread().split()))
    nxm = []
    for _ in range(q):
        nxm.append(list(map(int, sysread().split())))

    def check(n ,x, m):
        _d = [d[0] % m]
        for val in d[1:]:
            _d.append(_d[-1] + val % m)

        # n_step
        n_d = (n-1)// k
        n_rest = (n-1) % k
        x %= m
        _d_rest = 0 if n_rest == 0 else _d[n_rest-1]
        a_last = x + n_d * _d[k-1] + _d_rest
        n_step = a_last // m - x // m
        # n_same
        d0 = [1] if val == 0 else [0]
        for val in d[1:]:
            plus = 1 if val % m == 0 else 0
            d0.append(d0[-1] + plus)
        d0_rest = 0 if n_rest == 0 else d0[n_rest-1]
        n_same = n_d * d0[k-1] + d0_rest

        return n-1 - n_same - n_step

    for n, x, m in nxm:
        print(check(n, x, m))


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import combinations
def run():
    k,q = map(int, input().split())
    d = list(map(int,sysread().split()))
    nxm = []
    for _ in range(q):
        nxm.append(list(map(int, sysread().split())))

    def check(n ,x, m):
        _d = [val % m for val in d]
        # n_step
        n_d = (n-1)//k
        n_rest = (n-1)%k
        x %= m
        a_last = x + n_d * sum(_d) + sum(_d[:n_rest+1])
        n_step = a_last // m - x // m
        # n_same
        n_same = 0
        d0 = [1 if val == 0 else 0 for val in _d]
        n_same = n_d * sum(d0) + sum(d0[:n_rest+1])

        return n-1 - n_same - n_step

    for n, x, m in nxm:
        print(check(n, x, m))




def generate_inv(n,mod):
    """
    逆元行列
    n >= 2
    """
    ret = [0, 1]
    for i in range(2,n+1):
        next = -ret[mod%i] * (mod // i)
        next %= mod
        ret.append(next)
    return ret


def comb_mod(n, a, mod):
    """
    return: [n, a] % mod
    Note: mod must be a prime number
    """
    up = 1
    down = 1
    for i in range(a):
        up *= n - i
        up %= mod
        down *= i + 1
        down %= mod
    down = pow_mod(down, mod - 2, mod)
    return (up * down) % mod

def pow_mod(n, k, mod):
    res = 1
    while True:
        if k // 2 >= 1:
            if k % 2 == 1:
                res = (res * n) % mod
            n = (n ** 2) % mod
            k = k // 2
        else:
            break
    return (n * res) % mod


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
import sys
from copy import copy, deepcopy
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for CASES in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353

'''
# example input


'''
k, q = map(int, input().split())
A = list(map(int, input().split()))
for i in range(q):
    n, x, m = map(int, input().split())
    x %= m
    D = [a % m for a in A]
    SUM = [0]*(k+1)
    SUM[0] = D[0]
    for i in range(1, k):
        SUM[i] = SUM[i - 1] + D[i]
    tot = n - 1
    num = tot // k
    res = tot % k
    tot_zero = 0
    round_zero = 0
    for d in D:
        if d == 0:
            round_zero += 1
    for i in range(res):
        if D[i] == 0:
            tot_zero += 1
    tot_zero += num * round_zero

    num = (tot+1) // k
    res = (tot+1) % k
    a_tot = x+ num * SUM[k - 1]
    for i in range(1, res):
        a_tot = a_tot + D[(i - 1) % k]
    tot_big = (a_tot // m) - (x // m)
    # print(tot, tot_zero, tot_big)
    ans = tot - tot_zero - tot_big
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  import numpy as np
  k, q = map(int, input().split())
  d = np.array(list(map(int, input().split())))
  for i in range(q):
    n, x, m = map(int, input().split())
    x %= m
    d_mod = d % m
    zero_d = k - np.count_nonzero(d_mod)
    d_mod_sum = np.sum(d_mod) + m * zero_d
    rep = (n-1) // k
    rem = (n-1) % k
    zero_rem = len(d_mod[:rem]) - np.count_nonzero(d_mod[:rem])
    rem_sum = np.sum(d_mod[:rem]) + m * zero_rem
    ans = n - 1 - (x + d_mod_sum * rep + rem_sum) // m
    print(ans)
    print(rem_sum)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k,q = LI()
    d = LI()
    aa = [LI() for _ in range(q)]

    def f(n,x,m):
        e = [c%m for c in d]
        s = sum(e)
        t = s * (n//k)
        t += sum(e[:n%k])
        xt = x + t
        z = [1 if c == 0 else 0 for c in e]
        zs = sum(z) * (n//k) + sum(z[:n%k])
        print(xt, x, m)
        return n - 1 - (xt//m - x//m) - zs

    r = [f(n,x,m) for n,x,m in aa]
    return JA(r, "\n")


print(main())

Submission status: Wrong Answer

Solution code:
k, q = map(int, input().split())
d = list(map(int, input().split()))
queries = [tuple(map(int, input().split())) for _ in range(q)]

for n, x, m in queries:
    x_mod = x % m
    d_mod = [elem % m for elem in d]

    rem = n % k
    rem_d_mod = d_mod[-rem:]

    print(n - (x + sum(d_mod) * (n // k) + sum(rem_d_mod)) // m - d_mod.count(0) * (n // k) - rem_d_mod.count(0))

Submission status: Wrong Answer

Solution code:
#TLE
K,Q = map(int,input().split())
D = list(map(int,input().split()))
NXM = [tuple(map(int,input().split())) for i in range(Q)]

for N,X,M in NXM:
    ds = [d%M for d in D]
    a,b = divmod(N-1,K)
    s = 0
    z = 0
    for i,d in enumerate(ds):
        if d==0:
            z += 1
        if i==b:
            sb = s
            zb = z
        s += d
    x = (X + s*a + sb)//M - X//M
    y = z*a + zb
    print(N-1-x-y)

Submission status: Wrong Answer

Solution code:
k,q = map(int,input().split())
d = list(map(int,input().split()))
import numpy as np

for _ in range(q):
  n,x,m = map(int,input().split())
  dm = [a%m for a in d]
  q,r = divmod(n-1,len(dm))
  
  cumsum = np.cumsum(dm) 
  
  zero = q*dm.count(0) + dm[:r].count(0)
  
  alast = x + q*cumsum[-1] + cumsum[r-1]
  minus = alast//m - x//m
  
  print(n-1 - zero - minus)

Submission status: Wrong Answer

Solution code:
k,q = map(int,input().split())
d = list(map(int,input().split()))

for _ in range(q):
  n,x,m = map(int,input().split())
  dm = [a%m for a in d]
  q,r = divmod(n-1,len(dm))
  cumsum = [dm[0]]+ [dm[i]+dm[i-1] for i in range(1,k)]
  
  zero = q*dm.count(0) + dm[:r].count(0)
  
  alast = x + q*cumsum[-1] + cumsum[r-1]
  minus = alast//m - x//m
  
  print(n-1 - zero - minus)

Submission status: Wrong Answer

Solution code:
k,q = map(int,input().split())
d = list(map(int,input().split()))

for _ in range(q):
  n,x,m = map(int,input().split())
  dm = [a%m for a in d]
  
  zero = (n-1)//len(dm)*sum([a==0 for a in dm]) + sum(a==0 for a in dm[:(n-1)%len(dm)])
  
  alast = x + (n-1)//len(dm)*sum(dm) + sum(dm[:(n-1)%len(dm)])
  minus = alast//m - x//m
  print(zero,minus)
  print(n-1 - zero - minus)

Submission status: Wrong Answer

Solution code:
k,q = map(int,input().split())
d = list(map(int,input().split()))

for _ in range(q):
  n,x,m = map(int,input().split())
  dm = [a%m for a in d]
  
  zero = sum([a==0 for a in dm])
  
  alast = x + (n-1)//len(dm)*sum(dm) + sum(dm[:(n-1)%len(dm)])
  minus = alast//m - x//m
  
  print(n-1 - zero - minus)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    K, q = map(int, input().split())
    D_raw = list(map(int, input().split()))
    for _ in range(q):
        N, x, M = map(int, input().split())

        a = (N-1) % K
        b = (N-1) // K
        D = [0] * K
        zero_num = 0
        zero_num_2 = 0
        for i in range(K):
            d = D_raw[i]%M
            D[i] = d
            if not d:
                zero_num += 1
                if i < a:
                    zero_num_2 += 1
        ans = N - 1 - zero_num * b - zero_num_2 - (sum(D) * b + sum(D[:a]) + x) // M
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k, q = map(int, input().split())
d = list(map(int, input().split()))

for _ in range(q):
	n, x, m = map(int, input().split())

	res = 0
	for i in range(k):
		a = d[i] % m
		if d[i] % m == 0:
			a += m
		if (n-1) % k > i:
			res += a * (n//k + 1)
		else:
			res += a * (n//k)
	print( (n-1) - ((x+res)//m - x//m) )

Submission status: Wrong Answer

Solution code:
k, q = map(int, input().split())
d = list(map(int, input().split()))

for _ in range(q):
	n, x, m = map(int, input().split())

	res = 0
	for i in range(k):
		a = d[i] % m
		if d[i] % m == 0:
			a += m
		if n % k > i:
			res += a * (n//k + 1)
		else:
			res += a * (n//k)
	print( (n-1) - ((x+res)//m - x//m) )

Submission status: Wrong Answer

Solution code:
from math import ceil

if __name__ == "__main__":
    k, q = map(int, input().split())
    D = list(map(int, input().split()))
    N = [0] * q
    X = [0] * q
    M = [0] * q
    for i in range(q):
        N[i], X[i], M[i] = map(int, input().split())

    for i in range(q):
        n, x, m = N[i], X[i], M[i]
        last_x = x // m
        eq_cnt = 0
        for j in range(k):
            num = ceil((n - 1 - j) / k)
            last_x += (D[j] % m) * num
            if D[j] % m == 0:
                eq_cnt += num
        print((n - 1) - (last_x // m) - eq_cnt)

Submission status: Wrong Answer

Solution code:
from math import ceil

if __name__ == "__main__":
    k, q = map(int, input().split())
    d = list(map(int, input().split()))

    for i in range(q):
        n, x, m = map(int, input().split())
        last_x = x
        eq_cnt = 0
        for j in range(k):
            num = ceil((n - 1 - j) / k)
            last_x += (d[j] % m) * num
            if d[j] % m == 0:
                eq_cnt += num
        print((n - 1) - (last_x // m) - (x // m) - eq_cnt)

Submission status: Wrong Answer

Solution code:
from math import ceil

if __name__ == "__main__":
    k, q = map(int, input().split())
    d = list(map(int, input().split()))

    res = []
    for i in range(q):
        n, x, m = map(int, input().split())
        last_x = x
        eq_cnt = 0
        for j in range(k):
            num = ceil((n - 1 - j) / k)
            last_x += (d[j] % m) * num
            if d[j] % m == 0:
                eq_cnt += num
        res.append((n - 1) - (last_x // m) - (x // m) - eq_cnt)

    [print(r) for r in res]

Submission status: Wrong Answer

Solution code:
k,q = map(int,input().split())
d = [int(i) for i in input().split()]
#print(d)
for i in range(q):
    n,x,m = map(int,input().split())
    ans = n-1
    dm = [x%m for x in d[:k]]
    #print(dm)
    p, mod = divmod(n,k)
    #print(ans)
    ans = ans - dm[:mod].count(0)*(p+1) - dm[mod:].count(0)*p
    #print(ans)
    amax = x + (sum(dm[:mod])*(p+1) + sum(dm[mod:])*p)
    #print(x%m)
    ans -= ((amax//m) - (x//m))
    if x%m == amax%m:
        ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
k, q = map(int, input().split())
d = list(map(int, input().split()))

query = []
for _ in range(q):
    query.append(list(map(int, input().split())))

def answer_query(n, x, m):
    l = [d[i]%m for i in range(k)]
    n -= 1
    zero = l.count(0)
    count = n // k
    zero_total = zero*count
    rem = n % k
    s = sum(l)
    total = s%m * count + x%m
    for i in range(rem):
        total += l[i]
        if l[i] == 0:
            zero_total += 1

    total //= m
    #total += s//m * count

    print(n-total-zero_total)
for n, x, m in query:
    answer_query(n, x, m)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.buffer.readline
K, Q= map(int,input().split())
D = np.array(list(map(int,input().split()))).astype(np.int64)

ans = []
for i in range(Q):
    N,X,M = map(int,input().split())
    temp = 0
    tD = D % M
    sumtD = np.sum(tD)
    cumsumtD = np.cumsum(tD)
    zerocount = np.cumsum([tD == 0])
    nloop = (N-1)//K
    rsd = (N-1) - K*nloop
    #print(nloop,rsd)
    temp += nloop * zerocount[-1] + zerocount[rsd-1] if rsd else 0
    #print(temp)
    first = X % M
    last = first + sumtD * nloop + cumsumtD[rsd-1] if rsd else 0
    #print(first,last)
    temp += last//M - first//M
    #print(temp)
    ans.append(N-temp-1)

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

mod = 10**9+7 #出力の制限
N = 10**5 * 2
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

k,q = m()

d = l()


for i in range(q):
    n,x,mm = m()
    co = 0

    po = []
    for j in range(k):
        po.append(d[j] % mm)


    for j in range(k):
        if po[j] == 0:
            ccc = ((n-1)//k)
            if (n-1)%k >= j:
                ccc += 1
            co += ccc
    
    pp = sum(po) * ((n-1)//k)
    pp += x
    for j in range((n-1)%k):
        pp += po[j]
    
    co += (pp//mm) - (x//mm)
    
    print((n-co-1))

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

mod = 10**9+7 #出力の制限
N = 10**5 * 2
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

k,q = m()

d = l()


for i in range(q):
    n,x,mm = m()
    co = 0

    po = [d[j] % mm for j in range(k)]


    for j in range(k):
        if po[j] == 0:
            ccc = ((n-1)//k)
            if (n-1)%k == j:
                ccc += 1
            if ccc >= 0:
                co += ccc
    
    pp = sum(po) * ((n-1)//k)
    pp += x
    for j in range((n-1)%k):
        pp += po[j]
    
    co += pp//mm - x//mm
    
    print((n-co-1))