結果
問題 | No.1864 Shortest Paths Counting |
ユーザー |
![]() |
提出日時 | 2022-03-04 23:23:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,190 bytes |
コンパイル時間 | 958 ms |
コンパイル使用メモリ | 89,488 KB |
最終ジャッジ日時 | 2025-01-28 06:28:32 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 13 WA * 10 |
ソースコード
#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;}