結果

問題 No.743 Segments on a Polygon
ユーザー merom686merom686
提出日時 2018-10-05 22:30:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 81,896 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-26 18:08:14
合計ジャッジ時間 1,843 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
5,760 KB
testcase_01 AC 35 ms
5,632 KB
testcase_02 AC 37 ms
5,760 KB
testcase_03 AC 36 ms
5,760 KB
testcase_04 AC 36 ms
5,632 KB
testcase_05 AC 36 ms
5,760 KB
testcase_06 AC 37 ms
5,760 KB
testcase_07 AC 38 ms
5,760 KB
testcase_08 AC 37 ms
5,632 KB
testcase_09 AC 27 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    vector<int> b;
    int n;
};

struct E {
    bool operator<(const E& e) const {
        return b < e.b;
    }
    int a, b;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<E> e(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        e[i] = { a, b };
    }
    sort(e.begin(), e.end());

    BIT bt_a(m), bt_b(m);
    ll r = 0;
    for (int i = 0; i < n; i++) {
        r += bt_a.sum(e[i].a) - bt_b.sum(e[i].a);
        bt_a.add(e[i].a, 1);
        bt_b.add(e[i].b, 1);
    }

    cout << r << endl;

    return 0;
}
0