結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー 沙耶花沙耶花
提出日時 2023-02-24 22:10:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 531 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 4,737 ms
コンパイル使用メモリ 273,652 KB
実行使用メモリ 36,372 KB
最終ジャッジ日時 2023-10-11 06:20:32
合計ジャッジ時間 16,150 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
36,228 KB
testcase_01 AC 22 ms
36,168 KB
testcase_02 AC 22 ms
36,116 KB
testcase_03 AC 23 ms
36,224 KB
testcase_04 AC 22 ms
36,216 KB
testcase_05 AC 23 ms
36,184 KB
testcase_06 AC 22 ms
36,368 KB
testcase_07 AC 420 ms
36,252 KB
testcase_08 AC 438 ms
36,248 KB
testcase_09 AC 294 ms
36,372 KB
testcase_10 AC 420 ms
36,300 KB
testcase_11 AC 415 ms
36,304 KB
testcase_12 AC 284 ms
36,248 KB
testcase_13 AC 283 ms
36,244 KB
testcase_14 AC 272 ms
36,244 KB
testcase_15 AC 529 ms
36,204 KB
testcase_16 AC 531 ms
36,240 KB
testcase_17 AC 528 ms
36,236 KB
testcase_18 AC 528 ms
36,244 KB
testcase_19 AC 528 ms
36,208 KB
testcase_20 AC 528 ms
36,236 KB
testcase_21 AC 528 ms
36,252 KB
testcase_22 AC 527 ms
36,240 KB
testcase_23 AC 197 ms
36,240 KB
testcase_24 AC 281 ms
36,248 KB
testcase_25 AC 310 ms
36,172 KB
testcase_26 AC 215 ms
36,176 KB
testcase_27 AC 118 ms
36,040 KB
testcase_28 AC 355 ms
36,252 KB
testcase_29 AC 396 ms
36,248 KB
testcase_30 AC 135 ms
36,248 KB
testcase_31 AC 154 ms
36,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

using P = pair<mint,mint>;
P op(P a,P b){
	a.first += b.first;
	a.second += b.second;
	return a;
}

P e(){
	return make_pair(0,0);
}

P mapping(mint a,P b){
	b.first += a*b.second;
	return b;
}

mint composition(mint a,mint b){
	return a+b;
}

mint id(){
	return 0;
}

int main(){
	
	int H,W,K;
	cin>>H>>W>>K;
	vector<P> t(300000,make_pair(0,1));
	
	vector<lazy_segtree<P,op,e,mint,mapping,composition,id>> seg(2,
	lazy_segtree<P,op,e,mint,mapping,composition,id>(t));
	
	int C = 100001;
	vector<vector<pair<int,long long>>> vs(C*2);
	rep(i,K){
		int x,y,z;
		cin>>x>>y>>z;
		x--,y--;
		vs[x-y+C].emplace_back(x+y,z);
	}
	mint ans = 0;
	rep(i,C*2){
		int tt = i-C;
		int L=max(tt,-tt),R = min(2*(W-1)+tt,2*(H-1)-tt);
		if(L<=R){
			seg[L%2].apply(L/2,R/2+1,1);
		}
		rep(j,vs[i].size()){
			int y = vs[i][j].first;
			mint vv = vs[i][j].second;
			mint s = 0;
			if(y%2==0){
				s += seg[0].prod(0,y/2+1).first;
				s += seg[1].prod(0,y/2).first;
			}
			else{
				s += seg[0].prod(0,y/2+1).first;
				s += seg[1].prod(0,y/2+1).first;
			}
			ans += vv * s;
		}
	}
	cout<<ans.val()<<endl;
	
	return 0;
}
0