結果

問題 No.743 Segments on a Polygon
ユーザー t33ft33f
提出日時 2018-10-05 23:39:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 2,447 ms
コンパイル使用メモリ 62,824 KB
実行使用メモリ 4,928 KB
最終ジャッジ日時 2023-08-09 02:42:16
合計ジャッジ時間 2,723 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
4,908 KB
testcase_01 AC 68 ms
4,928 KB
testcase_02 AC 64 ms
4,852 KB
testcase_03 AC 66 ms
4,912 KB
testcase_04 AC 66 ms
4,904 KB
testcase_05 AC 64 ms
4,800 KB
testcase_06 AC 65 ms
4,756 KB
testcase_07 AC 66 ms
4,864 KB
testcase_08 AC 67 ms
4,828 KB
testcase_09 AC 58 ms
4,784 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