結果
問題 | No.743 Segments on a Polygon |
ユーザー | kotatsugame |
提出日時 | 2020-03-05 07:04:52 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 838 bytes |
コンパイル時間 | 615 ms |
コンパイル使用メモリ | 69,896 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-22 02:04:28 |
合計ジャッジ時間 | 2,594 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
6,816 KB |
testcase_01 | AC | 76 ms
6,944 KB |
testcase_02 | AC | 76 ms
6,944 KB |
testcase_03 | AC | 76 ms
6,940 KB |
testcase_04 | AC | 77 ms
6,944 KB |
testcase_05 | AC | 76 ms
6,940 KB |
testcase_06 | AC | 76 ms
6,940 KB |
testcase_07 | AC | 76 ms
6,940 KB |
testcase_08 | AC | 76 ms
6,944 KB |
testcase_09 | AC | 69 ms
6,940 KB |
コンパイルメッセージ
main.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 34 | main() | ^~~~
ソースコード
#include<iostream> using namespace std; //1-indexed #include<vector> template<typename T> struct BIT{ int n; vector<T>bit; BIT(int n_=0):n(n_),bit(n_+1){} T sum(int i) { T ans=0; for(;i>0;i-=i&-i)ans+=bit[i]; return ans; } void add(int i,T a) { if(i==0)return; for(;i<=n;i+=i&-i)bit[i]+=a; } int lower_bound(T k)//k<=sum(ret) { if(k<=0)return 0; int ret=0,i=1; while((i<<1)<=n)i<<=1; for(;i;i>>=1) if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i]; return ret+1; } }; int N,M; int id[2<<17]; int L[1<<17]; main() { cin>>N>>M; for(int i=1;i<=N;i++) { int a,b;cin>>a>>b; if(a>b)a^=b^=a^=b; L[i]=a; id[a]=i; id[b]=-i; } long ans=0; BIT<int>P(M); for(int i=0;i<M;i++) { if(id[i]>0)P.add(i+1,1); else { P.add(L[-id[i]]+1,-1); ans+=P.sum(i+1)-P.sum(L[-id[i]]); } } cout<<ans<<endl; }