QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770558#9543. Good PartitionsJEdwardWA 9ms10864kbPython31.9kb2024-11-21 22:22:072024-11-21 22:22:09

Judging History

你现在查看的是最新测评结果

  • [2024-11-21 22:22:09]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:10864kb
  • [2024-11-21 22:22:07]
  • 提交

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'