Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
26956 gaochunzhen 【BJ】T1 C++ 通过 100 922 MS 163820 KB 2470 2024-02-27 16:45:53

Tests(20/20):


#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; typedef long long LL; const int N = 309, M = 9e4 + 9; int n, m, q, type, a[N][N], lstans, ind[M], tp; int inx[N][N], b[N][N], p[N]; short cnt[N][N][N], rk[N][M]; signed main() { scanf("%d%d%d%d", &n, &m, &q, &type); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%d", &a[i][j]); ind[++tp] = a[i][j]; } } sort(ind + 1, ind + tp + 1); tp = unique(ind + 1, ind + tp + 1) - ind - 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { b[i][j] = lower_bound(ind + 1, ind + tp + 1, a[i][j]) - ind; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { inx[i][j] = a[i][j]; } sort(inx[i] + 1, inx[i] + m + 1); p[i] = unique(inx[i] + 1, inx[i] + m + 1) - inx[i] - 1; for (int j = 1; j <= m; j++) { int x = lower_bound(inx[i] + 1, inx[i] + p[i] + 1, a[i][j]) - inx[i]; cnt[j][x][i]++; } for (int j = m - 1; j >= 1; j--) { for (int k = 1; k <= p[i]; k++) { cnt[j][k][i] += cnt[j + 1][k][i]; } } for (int j = 1; j <= m; j++) { for (int k = p[i] - 1; k >= 1; k--) { cnt[j][k][i] += cnt[j][k + 1][i]; } } int k = p[i] + 1; for (int j = tp; j >= 1; j--) { if (ind[j] == inx[i][k - 1]) k--; rk[i][j] = k; } } while (q--) { int x1, y1, x2, y2, s, t; scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &s, &t); if (type) x1 ^= lstans, y1 ^= lstans, x2 ^= lstans, y2 ^= lstans, s ^= lstans, t ^= lstans; x1 = (x1 - 1 + n) % n + 1, x2 = (x2 - 1 + n) % n + 1, y1 = (y1 - 1 + m) % m + 1, y2 = (y2 - 1 + m) % m + 1; if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); if (s > t) swap(s, t); int s_ = lower_bound(ind + 1, ind + tp + 1, s) - ind, t_ = lower_bound(ind + 1, ind + tp + 1, t) - ind; int ans = 0; for (int i = x1; i <= x2; i++) { int _s = rk[i][s_], _t = rk[i][t_]; if (inx[i][_t] == t) _t++; ans += (cnt[y1][_s][i] - cnt[y1][_t][i]) - (cnt[y2 + 1][_s][i] - cnt[y2 + 1][_t][i]); } printf("%d\n", lstans = ans); } return 0; }


测评信息: