結果

問題 No.743 Segments on a Polygon
ユーザー HaarHaar
提出日時 2018-10-06 08:47:18
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 833 bytes
コンパイル時間 1,281 ms
コンパイル使用メモリ 152,968 KB
実行使用メモリ 4,764 KB
最終ジャッジ日時 2023-08-09 02:44:33
合計ジャッジ時間 2,942 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
4,704 KB
testcase_01 AC 69 ms
4,560 KB
testcase_02 AC 66 ms
4,536 KB
testcase_03 AC 69 ms
4,704 KB
testcase_04 AC 68 ms
4,764 KB
testcase_05 AC 69 ms
4,560 KB
testcase_06 AC 68 ms
4,592 KB
testcase_07 AC 66 ms
4,556 KB
testcase_08 AC 66 ms
4,628 KB
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

class BIT{
private:
  vector<int> tree;
  int n;
public:
  BIT(int size){tree.resize(size+1); for(auto v : tree){v = 0;}; n = size;}
  void update(int x, int a){while(x <= n){tree[x] += a; x += (x & (-x));}}
  int get(int x){int a = 0; while(x > 0){a += tree[x]; x -= (x & (-x));} return a;}
};

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int,int>> v(n);
  for(int i=0; i<n; ++i){
    int a,b;
    cin >> a >> b;
    v[i] = (a<b) ? make_pair(a,b) : make_pair(b,a);
  }

  sort(v.begin(), v.end(), [](const pair<int, int> &a, const pair<int, int> &b){return a.first < b.first;});
  
  BIT bit(m);
  int count = 0;

  for(int i=0; i<n; ++i){
    count += bit.get(v[i].second) - bit.get(v[i].first);
    bit.update(v[i].second,1);
  }

  cout << count << endl;
  
  return 0;
}
0