結果

問題 No.743 Segments on a Polygon
ユーザー どららどらら
提出日時 2018-10-05 23:36:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,105 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 170,540 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-02 17:23:00
合計ジャッジ時間 3,213 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct FenwickTree{
  static const int SIZE = 1<<20;
  int n, tree[SIZE+1];
public:
  FenwickTree(int n_){
    n = n_;
    for(int i=0; i<n+1; i++) tree[i] = 0;
  }
  void add(int i, int value){
    for(; i<n; i|=i+1) tree[i] += value;
  }
  int sum(int i){
    int s = 0;
    for(; i>=0; i=(i&i+1)-1) s += tree[i];
    return s;
  }
};

struct ST {
  int a, b;
};
bool operator<(const ST& a, const ST& b){
  return a.a < b.a;
}

int main(){
  int N, M;
  cin >> N >> M;

  vector<ST> v;
  rep(i,N){
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a,b);
    v.push_back((ST){a,b});
  }
  sort(ALLOF(v));
  
  FenwickTree ft(20);
  ll ret = 0;
  rep(i,N){
    int a = v[i].a, b = v[i].b;
    ll tmp = ft.sum(b) - ft.sum(a);
    ret += tmp;
    ft.add(b, 1);
  }

  cout << ret << endl;

  return 0;
}
0