結果
問題 | No.743 Segments on a Polygon |
ユーザー |
![]() |
提出日時 | 2018-10-05 22:43:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 1,217 bytes |
コンパイル時間 | 1,756 ms |
コンパイル使用メモリ | 202,900 KB |
最終ジャッジ日時 | 2025-01-06 14:19:32 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#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_backll 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;}