結果

問題 No.1864 Shortest Paths Counting
ユーザー pockynypockyny
提出日時 2022-03-04 23:23:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,190 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 94,012 KB
実行使用メモリ 14,868 KB
最終ジャッジ日時 2023-09-26 02:38:31
合計ジャッジ時間 6,997 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 208 ms
13,976 KB
testcase_10 WA -
testcase_11 AC 239 ms
13,924 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 237 ms
13,876 KB
testcase_16 AC 238 ms
13,804 KB
testcase_17 AC 236 ms
13,964 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 231 ms
13,960 KB
testcase_23 AC 207 ms
14,300 KB
testcase_24 WA -
testcase_25 AC 259 ms
13,868 KB
testcase_26 AC 118 ms
14,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef long long ll;
ll INF = 1000000000000000;
ll mod = 998244353;
struct segment_tree{
    int n; vector<ll> seg;
    segment_tree(){}
    segment_tree(int sz){n = sz; seg.resize(2*n);}
    segment_tree(vector<ll> v){
        n = v.size(); seg.resize(2*n);
        for(int i=0;i<n;i++) seg[i + n] = v[i];
        for(int i=n - 1;i>0;i--) seg[i] = (seg[i<<1] + seg[i<<1|1])%mod;
    }
    void init(int sz){n = sz; seg.resize(2*n);}
    void update(int p,ll val){
        for((seg[p += n] += val) %= mod;p>1;p>>=1) seg[p>>1] = (seg[p] + seg[p^1])%mod;
    }
    ll query(int l,int r){
        ll res = 0;
        for(l += n,r += n; l<r;l>>=1,r>>=1){
            if(l&1) res = (res + seg[l++])%mod;
            if(r&1) res = (res + seg[--r])%mod;
        }
        return res;
    }
    void clear(){for(int i=0;i<2*n;i++) seg[i] = 0;}
};

ll x[200010],y[200010];
int main(){
    int i,n; cin >> n;
    vector<pair<ll,ll>> v;
    for(i=0;i<n;i++){
        cin >> x[i] >> y[i];
        v.push_back({x[i] + y[i],x[i] - y[i]});
    }
    ll sx = x[0] + y[0],sy = x[0] - y[0];
    ll gx = x[n - 1] + y[n - 1],gy = x[n - 1] - y[n - 1];
    for(i=0;i<n;i++){
        if(sx>gx) v[i].first *= -1;
        if(sy>gy) v[i].second *= -1;
    }
    if(sx>gx) sx *= -1, gx *= -1;
    if(sy>gy) sy *= -1, gy *= -1;
    sort(v.begin(),v.end());
    /*for(auto p:v){
        cout << p.first << " " << p.second << endl;
    }
    cout << sx << " " << sy << " " << gx << " " << gy << endl;*/
    vector<ll> z(n + 1);
    for(i=0;i<n;i++) z[i] = v[i].second;
    sort(z.begin(),z.end());
    segment_tree seg(n);
    bool f = false;
    for(i=0;i<n;i++){
        if(v[i].first==sx && v[i].second==sy) f = true;
        if(!f) continue;
        int j = lower_bound(z.begin(),z.end(),v[i].second) - z.begin();
        ll num = seg.query(0,j + 1);
        if(v[i].first==sx && v[i].second==sy) num++;
        seg.update(j,num);
        if(v[i].first==gx && v[i].second==gy) f = false;
    }
    int j = lower_bound(z.begin(),z.end(),gy) - z.begin();
    //cout << j << endl;
    cout << seg.query(j,j + 1) << endl;
}
0