code transportation

Posted the-unbeatable

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了code transportation相关的知识,希望对你有一定的参考价值。

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

typedef double db;
const int N = 1e5 + 5;

int bit[N << 1], Bit[N << 1];
db tab[N << 1];
pair <db, db> p[N], q[N];

inline void Add(int p) {
  for (; p < N + N; p += p & (- p)) Bit[p] ++;
}

inline int Sum(int p) {
  int r = 0;
  for (; p > 0; p -= p & (- p)) r += Bit[p];
  return r;
}

inline void add(int p) {
  for (; p < N + N; p += p & (- p)) bit[p] ++;
}

inline int sum(int p) {
  int r = 0;
  for (; p > 0; p -= p & (- p)) r += bit[p];
  return r;
}

inline bool cmp(pair <db, db> a, pair <db, db> b) {
  return (fabs(a.first - b.first) <= 1e-8) ? a.second > b.second : a.first < b.first;
}

int main() {
  int n, w, c = 0, d = 0;
  scanf("%d%d", &n, &w);
  for (int i = 1, x, v; i <= n; i ++) {
    scanf("%d%d", &x, &v);
    if (x > 0) {
      p[++ c] = make_pair(1.0 * x / (- v - w), 1.0 * x / (- v + w));
      if (p[c].first > p[c].second) swap(p[c].first, p[c].second);
      tab[i + i - 1] = p[c].second;
      tab[i + i] = p[c].first;
    }
    else {
      q[++ d] = make_pair(1.0 * x / (- v - w), 1.0 * x / (- v + w));
      if (q[d].first > q[d].second) swap(q[d].first, q[d].second);
      tab[i + i - 1] = q[d].second;
      tab[i + i] = q[d].first;
    }
  }
  sort(p + 1, p + c + 1, cmp);
  sort(q + 1, q + d + 1, cmp);
  sort(tab + 1, tab + n + n + 1);
  long long ans = 0;
  for (int i = 1, pos; i <= c; i ++) {
    pos = lower_bound(tab + 1, tab + n + n + 1, p[i].second) - tab;
    ans += i - 1 - Sum(pos); Add(pos);
  }
  memset(Bit, 0, sizeof Bit);
  for (int i = 1, pos; i <= d; i ++) {
    pos = lower_bound(tab + 1, tab + n + n + 1, q[i].second) - tab;
    ans += i - 1 - Sum(pos); Add(pos);
  }
  memset(Bit, 0, sizeof Bit);
  for (int i = 1, pos; i <= c; i ++) {
    pos = lower_bound(tab + 1, tab + n + n + 1, p[i].first) - tab;
    add(n + n - pos + 1);
    pos = lower_bound(tab + 1, tab + n + n + 1, p[i].second) - tab;
    Add(pos);
  }
  for (int i = 1, l, r; i <= d; i ++) {
    l = lower_bound(tab + 1, tab + n + n + 1, q[i].first) - tab;
    r = lower_bound(tab + 1, tab + n + n + 1, q[i].second) - tab;
    ans += c - Sum(l - 1) - sum(n + n - (r + 1) + 1);
  }
  printf("%lld\n", ans);
  return 0;
}

以上是关于code transportation的主要内容,如果未能解决你的问题,请参考以下文章

VS code自定义用户代码片段snippet

Sublime Text自定制代码片段(Code Snippets)

vs code 自定义代码片段

VS Code配置markdown代码片段

VS Code配置markdown代码片段

vs code 用户代码片段 html.json