結果
| 問題 |
No.743 Segments on a Polygon
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2018-10-05 23:24:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,027 bytes |
| コンパイル時間 | 748 ms |
| コンパイル使用メモリ | 81,736 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-14 08:02:40 |
| 合計ジャッジ時間 | 1,770 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 a < e.a;
}
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(m);
ll r = 0;
for (int i = 0; i < n; i++) {
r += bt.sum(e[i].b) - bt.sum(e[i].a);
bt.add(e[i].b, 1);
}
cout << r << endl;
return 0;
}
merom686