結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー planesplanes
提出日時 2023-02-24 22:59:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,217 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 171,876 KB
実行使用メモリ 814,824 KB
最終ジャッジ日時 2023-10-11 06:46:31
合計ジャッジ時間 4,531 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 MLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll mod=998244353;


struct segtree {
ll n;
vector<ll> dat;
void init(ll n_) {
    n=1;
    while (n<n_) n*=2;
dat=vector<ll> (2*n-1,0LL);
}

    void update(ll k, ll a) {
        k+=n-1;
        dat[k]+=a;
  dat[k]%=mod;



        while(k>0) {
            k=(k-1)/2;
            dat[k]=dat[k*2+1]+dat[2*k+2];
        }
    }

    ll query (ll a, ll b, ll k,ll l, ll r) {

        if(r<=a||b<=l) return 0;

        if(a<=l&&r<=b) return dat[k];

        else {
            ll vl=query(a,b,k*2+1,l,(l+r)/2);
            ll vr=query(a,b,k*2+2,(l+r)/2,r);
            return vl+vr;
        }
    }

};


int main() {
  ll H,W,K;cin>>H>>W>>K;


vector<vector<ll>> memo(H,vector<ll> (W,0));


for(ll i=0;i<K;i++) {
  ll x,y,v;cin>>x>>y>>v;
  x--;y--;
  memo[x][y]+=v;

}




segtree p;
p.init(H+W+10);

ll ans=0;

 for(ll i=H-1;i>=1-W;i--) {


  for(ll t=max(0LL,i);t<H;t++) {
    p.update(t+(t-i),memo[t][t-i]);
  }
 
  for(ll t=max(0LL,i);t<H;t++) {
    ans+=p.query(t+t-i,H+W,0,0,p.n);
    ans%=mod;
  }
 }

 

cout<<ans<<endl;
}


0