結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー | ningenMe |
提出日時 | 2020-01-27 06:08:20 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 210 ms / 2,000 ms |
コード長 | 4,676 bytes |
コンパイル時間 | 2,050 ms |
コンパイル使用メモリ | 174,688 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-14 11:47:49 |
合計ジャッジ時間 | 3,636 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 210 ms
6,944 KB |
testcase_02 | AC | 115 ms
6,940 KB |
testcase_03 | AC | 110 ms
6,940 KB |
testcase_04 | AC | 104 ms
6,940 KB |
testcase_05 | AC | 103 ms
6,944 KB |
testcase_06 | AC | 103 ms
6,940 KB |
testcase_07 | AC | 100 ms
6,940 KB |
testcase_08 | AC | 105 ms
6,944 KB |
testcase_09 | AC | 105 ms
6,944 KB |
testcase_10 | AC | 104 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
evil_1 | AC | 119 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define ALL(obj) (obj).begin(),(obj).end() #define SPEED cin.tie(0);ios::sync_with_stdio(false); template<class T> using PQ = priority_queue<T>; template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>; constexpr long long MOD = (long long)1e9 + 7; constexpr long long MOD2 = 998244353; constexpr long long HIGHINF = (long long)1e18; constexpr long long LOWINF = (long long)1e15; constexpr long double PI = 3.1415926535897932384626433; template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);} template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));} template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}} template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;} template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;} template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;} template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;} template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;} void print(void) {cout << endl;} template <class Head> void print(Head&& head) {cout << head;print();} template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);} template <class T> void chmax(T& a, const T b){a=max(a,b);} template <class T> void chmin(T& a, const T b){a=min(a,b);} void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;} void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;} void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;} template<class T> class BinaryIndexedTree2D { //抽象化してない 一点加算、区間総和のみ const int N,M; vector<vector<T>> node; public: //1-indexed BinaryIndexedTree2D(const int& N,const int& M):N(N),M(M),node(N+1,vector<T>(M+1,0)){ // do nothing } inline T getvar(const int i,const int j){ T res = 0; for(int y=i;y>0;y-=(y&-y)) for(int x=j;x>0;x-=(x&-x)) { res += node[y][x]; } return res; } // [x1,x2] * [y1,y2] 1-indexed inline T getvar(const int y1,const int y2,const int x1,const int x2){ T res = 0; res += getvar(y1-1,x1-1); res -= getvar(y1-1,x2); res -= getvar(y2,x1-1); res += getvar(y2,x2); return res; } //add 1-indexed inline void update(const int i,const int j,T val){ for(int y=i;y&&y<=N;y+=(y&-y)) for(int x=j;x&&x<=M;x+=(x&-x)) { node[y][x]+=val; } } }; //verify https://atcoder.jp/contests/abc130/tasks/abc130_e int main() { SPEED int N,M; cin >> N >> M; auto cnt = multivector(M+2,M+2,0LL); auto sum = multivector(M+2,M+2,0LL); for(int i = 1; i <= M; ++i){ for(int j = 1; j <= M; ++j){ ll a; cin >> a; cnt[i][j]=a; } } for(int i = 0; i <= M; ++i){ for(int j = 0; j <= M; ++j){ cnt[i][j+1] += cnt[i][j]; } } for(int j = 0; j <= M; ++j){ for(int i = 0; i <= M; ++i){ cnt[i+1][j] += cnt[i][j]; } } for(int i = 1; i <= M; ++i){ for(int j = 1; j <= M; ++j){ for(int k = i; k <= M; ++k){ for(int l = j; l <= M; ++l){ ll z = cnt[k][l] - cnt[k][j-1] - cnt[i-1][l] + cnt[i-1][j-1]; if(z!=0) continue; sum[i][j]++; sum[i][l+1]--; sum[k+1][j]--; sum[k+1][l+1]++; } } } } for(int i = 0; i <= M; ++i){ for(int j = 0; j <= M; ++j){ sum[i][j+1] += sum[i][j]; } } for(int j = 0; j <= M; ++j){ for(int i = 0; i <= M; ++i){ sum[i+1][j] += sum[i][j]; } } for(int i = 0; i < N; ++i){ int x,y; cin >> x >> y; cout << sum[x][y] << endl; } return 0; }