結果

問題 No.743 Segments on a Polygon
ユーザー gazellegazelle
提出日時 2018-10-05 22:43:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 207,452 KB
実行使用メモリ 9,720 KB
最終ジャッジ日時 2023-08-09 02:40:41
合計ジャッジ時間 3,932 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
9,720 KB
testcase_01 AC 52 ms
8,464 KB
testcase_02 AC 53 ms
9,120 KB
testcase_03 AC 51 ms
9,276 KB
testcase_04 AC 50 ms
8,816 KB
testcase_05 AC 52 ms
9,428 KB
testcase_06 AC 52 ms
8,664 KB
testcase_07 AC 51 ms
8,656 KB
testcase_08 AC 52 ms
8,880 KB
testcase_09 AC 34 ms
8,368 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