結果

問題 No.1141 田グリッド
ユーザー ryoissyryoissy
提出日時 2020-07-31 22:15:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,849 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 174,360 KB
実行使用メモリ 13,332 KB
最終ジャッジ日時 2023-09-20 23:48:35
合計ジャッジ時間 8,255 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 80 ms
7,696 KB
testcase_14 AC 152 ms
13,332 KB
testcase_15 AC 227 ms
11,896 KB
testcase_16 AC 238 ms
11,844 KB
testcase_17 AC 234 ms
7,724 KB
testcase_18 AC 219 ms
7,748 KB
testcase_19 AC 247 ms
11,852 KB
testcase_20 AC 240 ms
11,848 KB
testcase_21 AC 238 ms
11,264 KB
testcase_22 AC 237 ms
11,320 KB
testcase_23 AC 237 ms
11,324 KB
testcase_24 AC 231 ms
7,624 KB
testcase_25 AC 213 ms
11,324 KB
testcase_26 AC 222 ms
7,724 KB
testcase_27 AC 229 ms
7,724 KB
testcase_28 AC 205 ms
11,260 KB
testcase_29 AC 224 ms
7,256 KB
testcase_30 AC 216 ms
7,668 KB
testcase_31 AC 255 ms
11,216 KB
testcase_32 AC 234 ms
11,216 KB
testcase_33 AC 237 ms
11,216 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
コンストラクタ ‘segtree::segtree(segtree&&)’ 内,
    inlined from ‘void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = segtree; _Args = {segtree}; _Tp = segtree]’ at /usr/local/gcc7/include/c++/12.2.0/bits/new_allocator.h:175:4,
    inlined from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = segtree; _Args = {segtree}; _Tp = segtree]’ at /usr/local/gcc7/include/c++/12.2.0/bits/alloc_traits.h:516:17,
    inlined from ‘void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {segtree}; _Tp = segtree; _Alloc = std::allocator<segtree>]’ at /usr/local/gcc7/include/c++/12.2.0/bits/vector.tcc:117:30,
    inlined from ‘void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = segtree; _Alloc = std::allocator<segtree>]’ at /usr/local/gcc7/include/c++/12.2.0/bits/stl_vector.h:1294:21,
    inlined from ‘void segtree2::init(int, int)’ at main.cpp:61:16:
main.cpp:7:7: 警告: ‘<名前なし>.segtree::N’ may be used uninitialized [-Wmaybe-uninitialized]
    7 | class segtree{
      |       ^~~~~~~
main.cpp: メンバ関数 ‘void segtree2::init(int, int)’ 内:
main.cpp:61:46: 備考: ‘<無名>’ はここで宣言されています
   61 |                         dp.push_back(segtree());
      |                                              ^

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	int N;
	vector<ll> dp;
	segtree(){
	}

	void init(int n){
		N=1;
		while(N<n){
			N*=2;
		}
		dp.clear();
		for(int i=0;i<N*2;i++){
			dp.push_back(1);
		}
	}


	void update(int k,ll v){
		k+=N-1;
		dp[k]=dp[k]*v%MOD;
		while(k>0){
			k=(k-1)/2;
			dp[k]=dp[k*2+1]*dp[k*2+2]%MOD;
		}
	}

	ll query(int a,int b,int k,int l,int r){
		if(b<=l || r<=a)return 1;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		ll vl=query(a,b,k*2+1,l,mid);
		ll vr=query(a,b,k*2+2,mid,r);
		return vl*vr%MOD;
	}

	ll query(int a,int b){
		return query(a,b,0,0,N);
	}
};

class segtree2{
public:
	int N;
	vector<segtree> dp;
	segtree2(){
	}
	void init(int n,int w){
		N=1;
		while(N<n){
			N*=2;
		}
		for(int i=0;i<N*2;i++){
			dp.push_back(segtree());
			dp[i].init(w);
		}
	}

	void update(int k,int w,ll v){
		k+=N-1;
		dp[k].update(w,v);
		while(k>0){
			k=(k-1)/2;
			dp[k].update(w,v);
		}
	}

	ll query(int a,int b,int ax,int bx,int k,int l,int r){
		if(b<=l || r<=a)return 1;
		if(a<=l && r<=b)return dp[k].query(ax,bx);
		int mid=(l+r)/2;
		ll vl=query(a,b,ax,bx,k*2+1,l,mid);
		ll vr=query(a,b,ax,bx,k*2+2,mid,r);
		return vl*vr%MOD;
	}

	ll query(int a,int b,int ax,int bx){
		return query(a,b,ax,bx,0,0,N);
	}
};

segtree2 segT;
int h,w,q;

int main(void){
	scanf("%d%d",&h,&w);
	segT.init(h,w);
	ll su=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			ll v;
			scanf("%lld",&v);
			//vec[i].push_back(v);
			segT.update(i,j,v);
		}
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int r,c;
		scanf("%d%d",&r,&c);
		r--;
		c--;
		ll ans=segT.query(0,r,0,c);
		ans=ans*segT.query(r+1,h,0,c)%MOD;
		ans=ans*segT.query(0,r,c+1,w)%MOD;
		ans=ans*segT.query(r+1,h,c+1,w)%MOD;
		printf("%lld\n",ans);
	}
	return 0;
}
0