結果

問題 No.743 Segments on a Polygon
ユーザー gazellegazelle
提出日時 2018-10-05 22:43:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 203,212 KB
実行使用メモリ 9,848 KB
最終ジャッジ日時 2024-04-26 18:09:28
合計ジャッジ時間 3,730 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
8,948 KB
testcase_01 AC 54 ms
8,648 KB
testcase_02 AC 56 ms
9,716 KB
testcase_03 AC 55 ms
9,848 KB
testcase_04 AC 57 ms
9,848 KB
testcase_05 AC 58 ms
9,592 KB
testcase_06 AC 56 ms
8,892 KB
testcase_07 AC 56 ms
8,948 KB
testcase_08 AC 56 ms
8,984 KB
testcase_09 AC 38 ms
9,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll N = 200020;
ll bit[200020];
void add(ll a, ll w) {
	a++;
	for (ll x = a; x <= N; x += x & -x) bit[x] += w;
}
ll sum(ll a) {
	a++;
	ll ret = 0;
	for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}
void init() {
	for(ll i=0; i < N; i++) bit[i] = 0;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	vector<int> b(n);
	REP(i,n) cin>>a[i]>>b[i];
	REP(i,n) if(a[i]>b[i]) swap(a[i],b[i]);
	vector<P> c;
	REP(i,n) c.pb(P(a[i],i));
	REP(i,n) c.pb(P(b[i],i));
	sort(ALL(c));
	ll ans=0;
	REP(i,2*n) {
		if(a[c[i].second]==c[i].first) {
			add(c[i].first, 1);
		} else {
			ans+=sum(c[i].first);
			ans-=sum(a[c[i].second]);
			add(a[c[i].second],-1);
		}
	}
	cout<<ans<<endl;
	return 0;
}
0