結果
問題 | No.743 Segments on a Polygon |
ユーザー |
![]() |
提出日時 | 2018-10-05 21:57:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 502 ms / 2,000 ms |
コード長 | 1,369 bytes |
コンパイル時間 | 591 ms |
コンパイル使用メモリ | 66,952 KB |
実行使用メモリ | 41,560 KB |
最終ジャッジ日時 | 2024-11-14 07:57:23 |
合計ジャッジ時間 | 6,354 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:47:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 47 | scanf("%d %d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:51:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 51 | scanf("%d %d", &a[i], &b[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <vector> using namespace std; const int N = 2 << 17; vector<int> seg[N * 2]; int lt(vector<int> &a, int x) { return lower_bound(a.begin(), a.end(), x) - a.begin(); } int gt(vector<int> &a, int x) { return a.end() - upper_bound(a.begin(), a.end(), x); } int lt(int l, int r, int x) { l += N; r += N; int res = 0; while (l < r) { if (l & 1) res += lt(seg[l++], x); if (r & 1) res += lt(seg[--r], x); l >>= 1; r >>= 1; } return res; } int gt(int l, int r, int x) { l += N; r += N; int res = 0; while (l < r) { if (l & 1) res += gt(seg[l++], x); if (r & 1) res += gt(seg[--r], x); l >>= 1; r >>= 1; } return res; } int main() { int n, m; scanf("%d %d", &n, &m); long long ans = 0; vector<int> a(m), b(m); for (int i = 0; i < n; i++) { scanf("%d %d", &a[i], &b[i]); if (a[i] > b[i]) { swap(a[i], b[i]); } seg[a[i] + N].push_back(b[i]); seg[b[i] + N].push_back(a[i]); } for (int i = N - 1; i >= 1; i--) { auto &x = seg[i * 2]; auto &y = seg[i * 2 + 1]; seg[i].resize(x.size() + y.size()); merge(x.begin(), x.end(), y.begin(), y.end(), seg[i].begin()); } for (int i = 0; i < m; i++) { ans += lt(a[i], b[i], a[i]); ans += gt(a[i], b[i], b[i]); } printf("%lld\n", ans / 2); return 0; }