結果
| 問題 |
No.743 Segments on a Polygon
|
| コンテスト | |
| ユーザー |
ats5515
|
| 提出日時 | 2018-10-05 21:51:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 2,000 ms |
| コード長 | 1,105 bytes |
| コンパイル時間 | 943 ms |
| コンパイル使用メモリ | 89,988 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-14 07:56:55 |
| 合計ジャッジ時間 | 2,011 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
template <class T>
struct fenwick_tree {
vector<T> x;
fenwick_tree(int n) : x(n, 0) { }
T sum(int i, int j) {
if (i == 0) {
T S = 0;
for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
return S;
}
else return sum(0, j) - sum(0, i - 1);
}
void add(int k, T a) {
for (; k < x.size(); k |= k + 1) x[k] += a;
}
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<pair<int, int> > A(N);
int res = 0;
for (int i = 0; i < N; i++) {
cin >> A[i].first >> A[i].second;
if (A[i].first > A[i].second)swap(A[i].first, A[i].second);
}
sort(A.begin(), A.end());
fenwick_tree<int> ft(M + 5);
int cur = 0;
int v = 0;
for (int i = 0; i < N; i++) {
while (cur < A[i].first) {
cur++;
}
res += ft.sum(0, A[i].second) - ft.sum(0, A[i].first);
ft.add(A[i].second , 1);
}
cout << res << endl;
}
ats5515