結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー planesplanes
提出日時 2023-02-25 11:22:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 2,486 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 179,592 KB
実行使用メモリ 21,356 KB
最終ジャッジ日時 2023-10-11 11:36:37
合計ジャッジ時間 12,655 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 377 ms
20,828 KB
testcase_08 AC 399 ms
20,604 KB
testcase_09 AC 188 ms
7,480 KB
testcase_10 AC 378 ms
21,000 KB
testcase_11 AC 375 ms
20,472 KB
testcase_12 AC 276 ms
19,548 KB
testcase_13 AC 275 ms
19,488 KB
testcase_14 AC 267 ms
19,268 KB
testcase_15 AC 488 ms
20,992 KB
testcase_16 AC 489 ms
21,196 KB
testcase_17 AC 489 ms
20,992 KB
testcase_18 AC 488 ms
21,124 KB
testcase_19 AC 491 ms
21,356 KB
testcase_20 AC 489 ms
21,072 KB
testcase_21 AC 485 ms
21,196 KB
testcase_22 AC 494 ms
21,052 KB
testcase_23 AC 166 ms
11,016 KB
testcase_24 AC 250 ms
12,744 KB
testcase_25 AC 272 ms
13,140 KB
testcase_26 AC 220 ms
16,644 KB
testcase_27 AC 117 ms
10,360 KB
testcase_28 AC 296 ms
13,472 KB
testcase_29 AC 360 ms
18,564 KB
testcase_30 AC 129 ms
10,784 KB
testcase_31 AC 142 ms
10,760 KB
権限があれば一括ダウンロードができます

ソースコード

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 LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
int main() {
  ll H,W,K;cin>>H>>W>>K;


LazySegmentTree p(vector<ll> (W+H,0));


vector<vector<pair<ll,ll>>> note(H+W,vector<pair<ll,ll>> (0));

for(ll i=0;i<K;i++) {
  ll x,y,v;cin>>x>>y>>v;
  x--;y--;
  note[x-y+W-1].push_back(make_pair(x+y,v));
}

ll ans=0;


for(ll k=1-W;k<=H-1;k++) {
  pair<ll,ll> x,y;
  if(-1*k>=0) {
    x=make_pair(0,-k);
  }
  else {
    x=make_pair(k,0);
  }

  if(k+W-1<=H-1) {
    y=make_pair(k+W-1,W-1);
  }
  else {
    y=make_pair(H-1,H-1-k);
  }

p.add(x.first+x.second,y.first+y.second+1,1);
if(x.first==0) {
  p.add(x.first+x.second,x.first+x.second+1,1);
}
if(k!=1-W&&y.second==W-1) {
  p.add(y.first+y.second,y.first+y.second+1,1);
}


for(auto t:note[k+W-1]) {
  ll now=p.getsum(0,t.first+1);


ll count=(t.first-x.first-x.second)/2;

now-=count;
now/=2;

  ans+=now%mod*t.second;
  ans%=mod;
}

}
ans%=mod;

if(ans<0) ans+=mod;
  
cout<<ans<<endl;
}
0