結果

問題 No.3313 Matryoshka
コンテスト
ユーザー t98slider
提出日時 2025-10-24 22:11:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 776 bytes
コンパイル時間 3,921 ms
コンパイル使用メモリ 253,536 KB
実行使用メモリ 19,036 KB
最終ジャッジ日時 2025-10-24 22:11:27
合計ジャッジ時間 9,413 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 4 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    constexpr int th = 1'000'000;
    vector<int> tb(th, -1), R(th), L(th);
    atcoder::fenwick_tree<int> fw(th);
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        l--, r--;
        tb[l] = r;
        R[r]++;
        L[l]++;
    }
    ll ans = (ll)(n - 1) * n / 2;
    for(int l = th - 1; l >= 0; l--){
        if(tb[l] == -1) continue;
        ans -= fw.sum(l, tb[l]);
        fw.add(l, 1);
        fw.add(tb[l], -1);
    }
    int lcnt = n;
    for(int i = 0; i < th; i++){
        lcnt -= L[i];
        ans -= (ll)(R[i]) * lcnt;
    }
    cout << ans << '\n';
}
0