結果

問題 No.743 Segments on a Polygon
ユーザー ats5515ats5515
提出日時 2018-10-05 21:51:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 84,036 KB
実行使用メモリ 6,372 KB
最終ジャッジ日時 2023-08-09 02:34:34
合計ジャッジ時間 2,463 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
6,160 KB
testcase_01 AC 37 ms
6,152 KB
testcase_02 AC 36 ms
6,372 KB
testcase_03 AC 36 ms
6,276 KB
testcase_04 AC 37 ms
6,284 KB
testcase_05 AC 36 ms
6,220 KB
testcase_06 AC 35 ms
6,176 KB
testcase_07 AC 35 ms
6,276 KB
testcase_08 AC 36 ms
6,280 KB
testcase_09 AC 27 ms
6,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0