Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
26951 gaochunzhen 【BJ】T1 C++ 运行超时 75 1038 MS 110260 KB 2470 2024-02-27 16:40:13

Tests(15/20):


#include <bits/stdc++.h> #pragma GCC optimize(2) 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[i][j][x]++; } for (int j = m - 1; j >= 1; j--) { for (int k = 1; k <= p[i]; k++) { cnt[i][j][k] += cnt[i][j + 1][k]; } } for (int j = 1; j <= m; j++) { for (int k = p[i] - 1; k >= 1; k--) { cnt[i][j][k] += cnt[i][j][k + 1]; } } 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[i][y1][_s] - cnt[i][y1][_t]) - (cnt[i][y2 + 1][_s] - cnt[i][y2 + 1][_t]); } printf("%d\n", lstans = ans); } return 0; }


测评信息: