結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー planesplanes
提出日時 2023-02-24 22:51:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,361 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 176,656 KB
実行使用メモリ 814,596 KB
最終ジャッジ日時 2023-10-11 06:40:50
合計ジャッジ時間 5,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
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<pair<ll,ll>>> note(H+W+10,vector<pair<ll,ll>> (0));

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;

}

for(ll i=0;i<H;i++) {
  for(ll j=0;j<W;j++) {
    note[i-j+W-1].push_back(make_pair(i+j,memo[i][j]));
  }
}


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

ll ans=0;
for(ll i=H+W;i>=0;i--) {
  for(auto x:note[i]) {
    p.update(x.first,x.second);
  }

  for(auto x:note[i]) {
    ans+=p.query(x.first,H+W,0,0,p.n);
    ans%=mod;
  }
}

cout<<ans<<endl;
}


0