結果

問題 No.755 Zero-Sum Rectangle
ユーザー ningenMeningenMe
提出日時 2020-01-27 06:03:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,371 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 173,672 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 12:48:19
合計ジャッジ時間 10,351 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
    BinaryIndexedTree2D<ll> bit(M+1,M+1);
    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;
            bit.update(i,j,a);
        }
    }
    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){
                    if(bit.getvar(i,k,j,l)!=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;
}
0