Submission #951906


Source Code Expand

#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>
#include <valarray>
#include <list>
 
using namespace std;
 
typedef long long ll;
 
template<class T>
struct Pi {
    T x, y;
    Pi() {}
    Pi(T xx, T yy) {
        x = xx; y = yy;
    }
    bool operator<(const Pi &r) const {
        if (x != r.x) return x < r.x;
        return y < r.y;
    }
    bool operator>(const Pi &r) const {
        if (x != r.x) return x > r.x;
        return y > r.y;
    }
    bool operator==(const Pi &r) const {
        if (x != r.x) return false;
        return y == r.y;
    }
};
 
template<class T>
struct Ti {
    T x, y, z;
    Ti() {}
    Ti(T xx, T yy, T zz) {
        x = xx; y = yy; z = zz;
    }
    bool operator<(const Ti &r) const {
        if (x != r.x) return x < r.x;
        if (y != r.y) return y < r.y;
        return z < r.z;
    }
    bool operator>(const Ti &r) const {
        if (x != r.x) return x > r.x;
        if (y != r.y) return y > r.y;
        return z > r.z;
    }
    bool operator==(const Ti &r) const {
        if (x != r.x) return false;
        if (y != r.y) return false;
        return z == r.z;
    }
};
 
const int MN = 520;
const int MK = 110;
int g[MN][MN];
int sum[MK][MN][MN] = {};
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> g[i][j]; g[i][j]--;
        }
    }
    for (int kk = 0; kk < k; kk++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                sum[kk][i][j] = sum[kk][i][j-1] + sum[kk][i-1][j]
                + (g[i-1][j-1] == kk) - sum[kk][i-1][j-1];
            }
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int t, a1, b1, a2, b2;
        cin >> t >> a1 >> b1 >> a2 >> b2;
        a1--; b1--;
        if (t == 1) {
            a2--; b2--;
            if (a1 > a2 || b1 > b2) {
                swap(a1, a2);
                swap(b1, b2);
            } 
            int k1 = g[a1][b1], k2 = g[a2][b2];
            swap(g[a1][b1], g[a2][b2]);
            int i, j;
            i = a1+1;
            for (int j = b1+1; j <= m; j++) {
                sum[k1][i][j] = sum[k1][i][j-1] + sum[k1][i-1][j]
                + (g[i-1][j-1] == k1) - sum[k1][i-1][j-1];
                sum[k2][i][j] = sum[k2][i][j-1] + sum[k2][i-1][j]
                + (g[i-1][j-1] == k2) - sum[k2][i-1][j-1];
            }
            j = b1 + 1;
            for (int i = a1+1; i <= n; i++) {
                sum[k1][i][j] = sum[k1][i][j-1] + sum[k1][i-1][j]
                + (g[i-1][j-1] == k1) - sum[k1][i-1][j-1];
                sum[k2][i][j] = sum[k2][i][j-1] + sum[k2][i-1][j]
                + (g[i-1][j-1] == k2) - sum[k2][i-1][j-1];
            }
        } else {
            int kk[100] = {};
            for (int i = 0; i < k; i++) {
                kk[i] = sum[i][a2][b2] - sum[i][a1][b2]
                - sum[i][a2][b1] + sum[i][a1][b1];
            }
            int ma = 0, mk = 0;
            for (int i = 0; i < k; i++) {
                if (ma <= kk[i]) {
                    ma = kk[i];
                    mk = i;
                }
            }
            printf("%d %d\n", mk+1, ma);
        }
    }
    return 0;
}

Submission Info

Submission Time
Task C - 宝探し 2
User yosupo
Language C++11 (GCC 4.8.1)
Score 100
Code Size 3595 Byte
Status AC
Exec Time 1595 ms
Memory 103720 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 19
Set Name Test Cases
All 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 AC 19 ms 800 KB
00-sample-01 AC 16 ms 792 KB
10-random_small-00 AC 307 ms 800 KB
10-random_small-01 AC 26 ms 1052 KB
10-random_small-02 AC 135 ms 2976 KB
10-random_small-03 AC 46 ms 1180 KB
10-random_small-04 AC 349 ms 1820 KB
10-random_small-05 AC 628 ms 11164 KB
10-random_small-06 AC 48 ms 1684 KB
10-random_small-07 AC 237 ms 3040 KB
10-random_small-08 AC 79 ms 21492 KB
20-random_large-00 AC 1589 ms 103712 KB
20-random_large-01 AC 1587 ms 103660 KB
20-random_large-02 AC 1595 ms 103712 KB
20-random_large-03 AC 1586 ms 103716 KB
20-random_large-04 AC 1589 ms 103716 KB
30-max_query-00 AC 1560 ms 103712 KB
30-max_query-01 AC 1563 ms 103720 KB
30-max_query-02 AC 1533 ms 103712 KB