結果

問題 No.1864 Shortest Paths Counting
ユーザー ぷらぷら
提出日時 2022-03-04 12:51:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 2,019 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 211,864 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-25 12:36:46
合計ジャッジ時間 8,098 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,388 KB
testcase_09 AC 122 ms
8,756 KB
testcase_10 AC 121 ms
8,504 KB
testcase_11 AC 102 ms
8,652 KB
testcase_12 AC 122 ms
8,584 KB
testcase_13 AC 119 ms
8,504 KB
testcase_14 AC 116 ms
8,504 KB
testcase_15 AC 106 ms
8,532 KB
testcase_16 AC 105 ms
8,592 KB
testcase_17 AC 101 ms
8,680 KB
testcase_18 AC 115 ms
8,536 KB
testcase_19 AC 113 ms
8,576 KB
testcase_20 AC 127 ms
8,440 KB
testcase_21 AC 126 ms
8,496 KB
testcase_22 AC 120 ms
8,500 KB
testcase_23 AC 123 ms
8,592 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 108 ms
8,748 KB
testcase_26 AC 92 ms
8,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

template <typename T>
struct BinaryIndexedTree {
    int N;
    vector<T>bit;
    BinaryIndexedTree(){}
    BinaryIndexedTree(int x) {
        N = x;
        bit.resize(x+1);
    }
    void add(int x,T y) {
        while(x <= N) {
            bit[x] += y;
            if(bit[x] >= mod) {
                bit[x] -= mod;
            }
            x += x&-x;
        }
    }
    T sum(int x) {
        T res = 0;
        while(x) {
            res += bit[x];
            if(res >= mod) {
                res -= mod;
            }
            x -= x&-x;
        }
        return res;
    }
    inline T sum(int l, int r) {//[l,r]
        int res = sum(r)-sum(l-1);
        if(res < 0) res += mod;
        return res;
    }
    inline T operator[](int k) {
        return sum(k)-sum(k-1);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int>X(N),Y(N);
    for(int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
        X[i] = X[i]+Y[i];
        Y[i] = X[i]-Y[i]*2;
    }
    if(X[0] > X[N-1]) {
        for(int i = 0; i < N; i++) {
            X[i] = -X[i];
        }
    }
    if(Y[0] > Y[N-1]) {
        for(int i = 0; i < N; i++) {
            Y[i] = -Y[i];
        }
    }
    vector<array<int,3>>tmp(N);
    vector<int>cmp(N);
    for(int i = 0; i < N; i++) {
        tmp[i][0] = X[i],tmp[i][1] = Y[i],tmp[i][2] = i;
        cmp[i] = Y[i];
    }
    sort(tmp.begin(),tmp.end());
    sort(cmp.begin(),cmp.end());
    cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
    BinaryIndexedTree<int>bit(cmp.size());
    for(int i = 0; i < N; i++) {
        int it = lower_bound(cmp.begin(),cmp.end(),tmp[i][1])-cmp.begin();
        if(tmp[i][2] == N-1) {
            cout << bit.sum(1,it+1) << endl;
            return 0;
        }
        if(tmp[i][2] == 0) {
            bit.add(it+1,1);
        }
        else {
            bit.add(it+1,bit.sum(1,it+1));
        }
    }
}
0