結果
| 問題 | No.755 Zero-Sum Rectangle | 
| コンテスト | |
| ユーザー |  gazelle | 
| 提出日時 | 2018-12-03 00:59:17 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 122 ms / 2,000 ms | 
| コード長 | 2,014 bytes | 
| コンパイル時間 | 1,242 ms | 
| コンパイル使用メモリ | 125,624 KB | 
| 最終ジャッジ日時 | 2025-01-06 17:58:35 | 
| ジャッジサーバーID (参考情報) | judge5 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 11 TLE * 1 | 
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
/* --------------------------------------- */
class AccumulSum {
public:
	AccumulSum(int h,int w,vector<vector<ll> >& a) {
		_h=h;
		_w=w;
		_sum.resize(_h+1);
		for(int i=0; i<_h+1; ++i) {
			_sum[i].resize(_w+1);
			for(int j=0; j<_w+1; ++j) {
				if(i==0||j==0) _sum[i][j]=0;
				else _sum[i][j]=a[i-1][j-1];
			}
		}
		for(int i=0; i<_h+1; ++i) {
			for(int j=1; j<_w+1; ++j) _sum[i][j]+=_sum[i][j-1];
		}
		for(int i=0; i<_w+1; ++i) {
			for(int j=1; j<_h+1; ++j) _sum[j][i]+=_sum[j-1][i];
		}
	}
	// the coordinates of ul and dr should be 0-indexed
	long long query(pair<int,int> ul,pair<int,int> dr) {
		ll ret=0;
		ret+=_sum[dr.first+1][dr.second+1];
		ret-=_sum[dr.first+1][ul.second];
		ret-=_sum[ul.first][dr.second+1];
		ret+=_sum[ul.first][ul.second];
		return ret;
	}
private:
	int _h;
	int _w;
	vector<vector<ll> > _sum;
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vector<vector<ll>> a(m,vector<ll>(m));
	REP(i,m) REP(j,m) cin >> a[i][j];
	AccumulSum acm(m, m, a);
	REP(query,n) {
		ll x, y;
		cin >> x >> y;
		x--;
		y--;
		ll ans = 0;
		for(ll i = 0; i <= x; i++) for(ll j = 0; j <= y; j++) {
			for(ll k = x; k < m; k++) for(ll l = y; l < m; l++) {
				if(acm.query(P(i, j), P(k, l)) == 0) ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
/* --------------------------------------- */
            
            
            
        