結果

問題 No.755 Zero-Sum Rectangle
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-12-12 20:55:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 2,643 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 168,780 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 17:37:02
合計ジャッジ時間 5,316 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 203 ms
4,376 KB
testcase_02 AC 143 ms
4,376 KB
testcase_03 AC 134 ms
4,376 KB
testcase_04 AC 129 ms
4,380 KB
testcase_05 AC 125 ms
4,380 KB
testcase_06 AC 123 ms
4,376 KB
testcase_07 AC 122 ms
4,380 KB
testcase_08 AC 122 ms
4,376 KB
testcase_09 AC 123 ms
4,380 KB
testcase_10 AC 123 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
evil_1 AC 143 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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]);
    }
}
0