結果
| 問題 | No.743 Segments on a Polygon | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2018-10-05 22:30:27 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 38 ms / 2,000 ms | 
| コード長 | 1,073 bytes | 
| コンパイル時間 | 822 ms | 
| コンパイル使用メモリ | 81,256 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-14 08:01:02 | 
| 合計ジャッジ時間 | 1,960 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
ソースコード
#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;
}
            
            
            
        