Submission #14612914


Source Code Expand

Copy
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(A, K, query):
    H, W = A.shape
    dp = np.zeros((H, W + 1, K + 1), np.int64)
    for h in range(H):
        for w in range(W):
            dp[h, w + 1] = dp[h, w]
            k = A[h, w]
            dp[h, w + 1, k] += 1

    def update(dp, h, k):
        for w in range(W):
            dp[h, w + 1, k] = dp[h, w, k] + (A[h, w] == k)

    for i in range(len(query)):
        t, a, b, c, d = query[i]
        a, b, c, d = a - 1, b - 1, c - 1, d - 1
        if t == 1:
            k1, k2 = A[a, b], A[c, d]
            A[a, b], A[c, d] = k2, k1
            update(dp, a, k1)
            update(dp, c, k1)
            update(dp, a, k2)
            update(dp, c, k2)
        elif t == 2:
            count = np.zeros(K + 1, np.int32)
            for h in range(a, c + 1):
                count += dp[h, d + 1] - dp[h, b]
            k = K - np.argmax(count[::-1])
            print(k, count[k])

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i4 = numba.int32
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i4[:, :], i4, i4[:, :]))
    cc.compile()

from my_module import main

N, M, K = map(int, readline().split())
A = np.array([list(map(int, readline().split())) for _ in range(N)], np.int32)
Q = int(readline())
query = np.array(read().split(), np.int32).reshape(Q, 5)

main(A.copy(), K, query)

Submission Info

Submission Time
Task C - 宝探し 2
User maspy
Language Python (3.8.2)
Score 0
Code Size 1652 Byte
Status
Exec Time 5519 ms
Memory 230204 KB

Judge Result

Set Name Score / Max Score Test Cases
All 0 / 100 00-sample-00, 00-sample-01, 10-random_small-00, 10-random_small-01, 10-random_small-02, 10-random_small-03, 10-random_small-04, 10-random_small-05, 10-random_small-06, 10-random_small-07, 10-random_small-08, 20-random_large-00, 20-random_large-01, 20-random_large-02, 20-random_large-03, 20-random_large-04, 30-max_query-00, 30-max_query-01, 30-max_query-02
Case Name Status Exec Time Memory
00-sample-00 113 ms 27408 KB
00-sample-01 112 ms 27032 KB
10-random_small-00 210 ms 34372 KB
10-random_small-01 118 ms 27052 KB
10-random_small-02 143 ms 29088 KB
10-random_small-03 129 ms 28400 KB
10-random_small-04 295 ms 46436 KB
10-random_small-05 395 ms 48200 KB
10-random_small-06 135 ms 28392 KB
10-random_small-07 269 ms 38788 KB
10-random_small-08 141 ms 35164 KB
20-random_large-00 5243 ms 229664 KB
20-random_large-01 5207 ms 230116 KB
20-random_large-02 5211 ms 229120 KB
20-random_large-03 5225 ms 229912 KB
20-random_large-04 5266 ms 229756 KB
30-max_query-00 5519 ms 230204 KB
30-max_query-01 5519 ms 230088 KB
30-max_query-02 5519 ms 230168 KB