結果
| 問題 |
No.755 Zero-Sum Rectangle
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2018-12-12 20:55:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 162 ms / 2,000 ms |
| コード長 | 2,643 bytes |
| コンパイル時間 | 1,573 ms |
| コンパイル使用メモリ | 170,584 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 02:17:51 |
| 合計ジャッジ時間 | 3,620 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int VW, int VH> struct Ruisekiwa2D {
ll v[VH][VW];
void set(int x, int y, ll c) { v[y][x] = c; }
void build() {
rep(y, 0, VH) rep(x, 0, VW) {
if (0 < y) v[y][x] += v[y - 1][x];
if (0 < x) v[y][x] += v[y][x - 1];
if (0 < y && 0 < x) v[y][x] -= v[y - 1][x - 1];
}
}
ll get(int sx, int sy, int tx, int ty) {
assert(sx <= tx && sy <= ty);
ll rs = v[ty][tx];
if (0 < sx) rs -= v[ty][sx - 1];
if (0 < sy) rs -= v[sy - 1][tx];
if (0 < sx && 0 < sy) rs += v[sy - 1][sx - 1];
return rs;
}
};
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, M, A[150][150];
Ruisekiwa2D<150, 150> r2d;
int ans[150][150];
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> M;
rep(y, 0, M) rep(x, 0, M) cin >> A[y][x];
rep(y, 0, M) rep(x, 0, M) r2d.set(y, x, A[y][x]);
r2d.build();
rep(sy, 0, M) rep(ty, sy, M) rep(sx, 0, M) rep(tx, sx, M) {
if (r2d.get(sx, sy, tx, ty) == 0) {
ans[sy][sx]++;
ans[ty + 1][sx]--;
ans[sy][tx + 1]--;
ans[ty + 1][tx + 1]++;
}
}
rep(y, 0, M) rep(x, 1, M) ans[y][x] += ans[y][x - 1];
rep(x, 0, M) rep(y, 1, M) ans[y][x] += ans[y - 1][x];
rep(i, 0, N) {
int x, y; cin >> x >> y;
x--; y--;
printf("%d\n", ans[y][x]);
}
}
はまやんはまやん