結果
| 問題 | No.743 Segments on a Polygon | 
| コンテスト | |
| ユーザー |  t33f | 
| 提出日時 | 2018-10-05 23:39:32 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 74 ms / 2,000 ms | 
| コード長 | 600 bytes | 
| コンパイル時間 | 475 ms | 
| コンパイル使用メモリ | 61,044 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-14 08:03:31 | 
| 合計ジャッジ時間 | 1,949 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
ソースコード
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    pair<int, int> a[100000];
    int bit[200002] = {};
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        if (x > y) swap(x, y);
        a[i] = make_pair(x, y);
    }
    sort(a, a+n);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int x = a[i].second; x > 0; x -= x&-x) ans += bit[x];
        for (int x = a[i].first; x > 0; x -= x&-x) ans -= bit[x];
        for (int x = a[i].second; x <= m; x += x&-x) bit[x]++;
    }
    cout << ans << endl;
}
            
            
            
        