結果
| 問題 |
No.743 Segments on a Polygon
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-10-05 21:52:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,328 bytes |
| コンパイル時間 | 3,317 ms |
| コンパイル使用メモリ | 200,396 KB |
| 実行使用メモリ | 177,336 KB |
| 最終ジャッジ日時 | 2024-10-12 13:04:40 |
| 合計ジャッジ時間 | 9,201 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 9 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
template <typename T>
using gtree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// usage:
// find_by_order(Int k): return the iterator of k-th smallest element (0-indexed)
// order_of_key(T key): return the index of key in tree
//INSERT ABOVE HERE
signed main(){
using T = gtree<Int>;
Int n,m;
cin>>n>>m;
vector<Int> a(n),b(n);
for(Int i=0;i<n;i++) cin>>a[i]>>b[i];
Int h=0;
while((1<<h)<m) h++;
vector<T> dat(2<<h);
auto calc=
[&](T &G,Int x,Int y)->Int{
return G.order_of_key(y)-G.order_of_key(x);
};
// [a, b) * [x, y)
auto query=
[&](Int a,Int b,Int x,Int y){
Int res=0;
for(Int l=a+m,r=b+m;l<r;l>>=1,r>>=1){
if(l&1) res+=calc(dat[l++],x,y);
if(r&1) res+=calc(dat[--r],x,y);
}
return res;
};
auto update=
[&](Int a,Int b){
a+=m;
while(a){
dat[a].insert(b);
a>>=1;
}
};
Int ans=0;
for(Int i=0;i<n;i++){
if(a[i]>b[i]) swap(a[i],b[i]);
ans+=query(0,a[i],a[i],b[i]);
ans+=query(a[i],b[i],b[i],m);
update(a[i],b[i]);
}
cout<<ans<<endl;
return 0;
}
beet