結果

問題 No.1864 Shortest Paths Counting
ユーザー shiomusubi496shiomusubi496
提出日時 2022-01-05 16:27:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 1,542 bytes
コンパイル時間 2,739 ms
コンパイル使用メモリ 212,224 KB
実行使用メモリ 9,464 KB
最終ジャッジ日時 2023-09-23 13:35:32
合計ジャッジ時間 8,470 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 255 ms
7,820 KB
testcase_10 AC 258 ms
7,840 KB
testcase_11 AC 257 ms
7,840 KB
testcase_12 AC 265 ms
8,724 KB
testcase_13 AC 256 ms
7,992 KB
testcase_14 AC 259 ms
7,992 KB
testcase_15 AC 263 ms
8,272 KB
testcase_16 AC 257 ms
7,892 KB
testcase_17 AC 260 ms
8,148 KB
testcase_18 AC 259 ms
8,268 KB
testcase_19 AC 256 ms
7,988 KB
testcase_20 AC 260 ms
8,192 KB
testcase_21 AC 257 ms
7,924 KB
testcase_22 AC 260 ms
7,924 KB
testcase_23 AC 257 ms
7,860 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 234 ms
9,464 KB
testcase_26 AC 185 ms
7,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 998244353;

class BinaryIndexedTree {
private:
    int n;
    vector<ll> data;
public:
    BinaryIndexedTree(int n) : n(n), data(n + 1) {}
    void add(int k, ll x) {
        for (++k; k <= n; k += k & -k) (data[k] += x) %= mod;
    }
    ll sum(int k) {
        ll res = 0;
        for (; k; k -= k & -k) (res += data[k]) %= mod;
        return res;
    }
};

int compress(vector<ll>& A) {
    auto B = A;
    sort(B.begin(), B.end());
    B.erase(unique(B.begin(), B.end()), B.end());
    for (auto&& i : A) {
        i = lower_bound(B.begin(), B.end(), i) - B.begin();
    }
    return B.size();
}

int main() {
    int N; cin >> N;
    vector<ll> X(N), Y(N);
    for (int i=0; i<N; ++i) {
        ll a, b; cin >> a >> b;
        X[i] = a + b;
        Y[i] = a - b;
    }
    if (X.front() > X.back()) {
        for (auto&& i : X) i = -i;
    }
    if (Y.front() > Y.back()) {
        for (auto&& i : Y) i = -i;
    }
    compress(X);
    int K = compress(Y);
    vector<pair<int, int>> A;
    for (int i=0; i<N; ++i) {
        if (X.front() > X[i] || X[i] > X.back()) continue;
        if (Y.front() > Y[i] || Y[i] > Y.back()) continue;
        A.emplace_back(X[i], Y[i]);
    }
    int M = A.size();
    sort(A.begin(), A.end());
    BinaryIndexedTree BIT(K);
    for (int i=0; i<M; ++i) {
        if (i == 0) BIT.add(0, 1);
        else if (i == M - 1) cout << BIT.sum(K) << endl;
        else BIT.add(A[i].second, BIT.sum(A[i].second + 1));
    }
}
0