QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#770558 | #9543. Good Partitions | JEdward | WA | 9ms | 10864kb | Python3 | 1.9kb | 2024-11-21 22:22:07 | 2024-11-21 22:22:09 |
Judging History
answer
import sys
import math
def get_divisors(x):
divisors = set()
for i in range(1, int(math.isqrt(x)) + 1):
if x % i == 0:
divisors.add(i)
divisors.add(x // i)
return divisors
def solve():
input = sys.stdin.read
data = input().split()
idx = 0
T = int(data[idx])
idx += 1
for _ in range(T):
n = int(data[idx])
q = int(data[idx + 1])
idx += 2
a = list(map(int, data[idx:idx + n]))
idx += n
# Initial calculation
S = set()
for s in range(n - 1):
if a[s] > a[s + 1]:
S.add(s + 1) # 1-based positions
if not S:
print(n)
else:
g = 0
for s in S:
g = math.gcd(g, s)
divisors = get_divisors(g)
print(len(divisors))
# Process queries
for _ in range(q):
p = int(data[idx]) # 1-based
v = int(data[idx + 1])
idx += 2
a[p - 1] = v
# Update S for position p-1 and p
if p > 1:
prev = a[p - 2] > a[p - 1]
curr = a[p - 2] > a[p - 1]
if prev and not curr:
S.discard(p - 1)
elif not prev and curr:
S.add(p - 1)
if p < n:
prev = a[p - 1] > a[p]
curr = a[p - 1] > a[p]
if prev and not curr:
S.discard(p)
elif not prev and curr:
S.add(p)
if not S:
print(n)
else:
g = 0
for s in S:
g = math.gcd(g, s)
divisors = get_divisors(g)
print(len(divisors))
if __name__ == '__main__':
solve()
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 9ms
memory: 10864kb
input:
1 5 2 4 3 2 6 1 2 5 3 5
output:
1 1 1
result:
wrong answer 2nd lines differ - expected: '2', found: '1'