結果

問題 No.743 Segments on a Polygon
ユーザー risujirohrisujiroh
提出日時 2018-10-05 22:01:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,373 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 170,688 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-14 07:57:43
合計ジャッジ時間 2,586 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }
template<class T> struct BIT {
int n, h;
V<T> t;
BIT(int n) : n(n), h(__lg(n) + 1) { t.assign(n + 1, (T) 0); }
void add(int x, T a) {
for (int i = x + 1; i < n + 1; i += i & -i) t[i] += a;
}
int lower_bound(T s) {
if (s <= 0) return 0;
int res = 0;
for (int k = 1 << h - 1; k; k >>= 1) if (res + k < n + 1 and t[res + k] < s) s -= t[res += k];
return res + 1;
}
T sum(int x) {
T res = 0;
for (int i = x; i; i -= i & -i) res += t[i];
return res;
}
T sum(int l, int r) {
return sum(r) - sum(l);
}
};
int main() {
cin.tie(NULL); ios::sync_with_stdio(false);
int n, m; cin >> n >> m;
V<> p(m, -1), q(m);
for (int i = 0; i < n; i++) {
int a, b; cin >> a >> b;
if (a > b) swap(a, b);
p[b] = i;
q[b] = a;
}
lint res = 0;
BIT<int> bit(m);
for (int i = 0; i < m; i++) {
if (p[i] == -1) bit.add(i, 1);
else {
res += bit.sum(q[i] + 1, i);
bit.add(q[i], -1);
}
}
cout << res << '\n';
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0