結果
| 問題 |
No.755 Zero-Sum Rectangle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-31 19:53:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 162 ms / 2,000 ms |
| コード長 | 1,652 bytes |
| コンパイル時間 | 1,760 ms |
| コンパイル使用メモリ | 175,436 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 22:41:50 |
| 合計ジャッジ時間 | 3,081 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
array<array<ll,131>,131> A{};
array<array<int,131>,131> B{};
int n, m;
cin >> n >> m;
for(int y = 1; y <= m; y++){
for(int x = 1; x <= m; x++){
cin >> A[y][x];
A[y][x] += A[y][x - 1] + A[y - 1][x] - A[y - 1][x - 1];
}
}
vector<pair<ll,int>> temp(m + 1);
ll offset;
for(int ly = 0; ly < m; ly++){
for(int ry = ly + 1; ry <= m; ry++){
temp[0] = make_pair(0, 0);
offset = -A[ry][0] + A[ly][0];
for(int x = 1; x <= m; x++){
temp[x] = make_pair(A[ry][x] - A[ly][x] + offset, x);
}
sort(temp.begin(), temp.end());
for(int i = 0; i < m; ){
int p = i++;
while(i <= m && temp[i].first == temp[p].first) i++;
for(int j = p; j + 1 < i; j++){
for(int k = j + 1; k < i; k++){
B[ry][temp[k].second]++;
B[ly][temp[k].second]--;
B[ry][temp[j].second]--;
B[ly][temp[j].second]++;
}
}
}
}
}
for(int i = 0; i < 131; i++) {
for(int j = 1; j < 131; j++) {
B[i][j] += B[i][j - 1];
}
}
for(int i = 0; i < 131; i++) {
for(int j = 1; j < 131; j++) {
B[j][i] += B[j - 1][i];
}
}
while(n--){
int y, x;
cin >> y >> x;
cout << B[--y][--x] << '\n';
}
}