結果

問題 No.743 Segments on a Polygon
ユーザー t33ft33f
提出日時 2018-10-05 23:39:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 61,052 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 18:10:57
合計ジャッジ時間 1,934 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
5,248 KB
testcase_01 AC 73 ms
5,376 KB
testcase_02 AC 68 ms
5,376 KB
testcase_03 AC 69 ms
5,376 KB
testcase_04 AC 66 ms
5,376 KB
testcase_05 AC 69 ms
5,376 KB
testcase_06 AC 69 ms
5,376 KB
testcase_07 AC 70 ms
5,376 KB
testcase_08 AC 66 ms
5,376 KB
testcase_09 AC 59 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0