結果

問題 No.743 Segments on a Polygon
ユーザー chocoruskchocorusk
提出日時 2018-10-05 21:45:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 1,428 ms
コンパイル使用メモリ 80,284 KB
実行使用メモリ 5,028 KB
最終ジャッジ日時 2023-08-09 02:32:10
合計ジャッジ時間 2,640 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
4,720 KB
testcase_01 AC 71 ms
4,676 KB
testcase_02 AC 71 ms
4,856 KB
testcase_03 AC 69 ms
4,652 KB
testcase_04 AC 69 ms
5,028 KB
testcase_05 AC 70 ms
4,764 KB
testcase_06 AC 68 ms
4,680 KB
testcase_07 AC 68 ms
4,716 KB
testcase_08 AC 68 ms
4,668 KB
testcase_09 AC 61 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int bit[200001], m;
 
int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i-=(i&(-i));
	}
	return s;
}
 
void add(int i){
	while(i<=m){
		bit[i]+=1;
		i+=(i&(-i));
	}
}

int main()
{
	int n; cin>>n>>m;
  vector<P> v;
  for(int i=0; i<n; i++){
      int a, b; cin>>a>>b; a++; b++;
    if(a>b) swap(a, b);
    v.push_back(P(a, b));
  }
  sort(v.begin(), v.end());
  ll ans=0;
  for(int i=0; i<n; i++){
    int a=v[i].first, b=v[i].second;
    ans+=((ll)(sum(b)-sum(a)));
    add(b);
  }
  cout<<ans<<endl;
	return 0;
}
0