Codeforces 989D A Shade of Moonlight

Posted cjlhy

tags:

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

A Shade of Moonlight

列列式子发现, 对于同一个云来说只有反向的云才能和它相交, 然后我们发现这个东西有单调性,然后二分就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long

using namespace std;

const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1);

int n, l, w;
vector<int> a;
vector<int> b;

bool check(int x1, int x2) {
    return abs(x1 + x2 + l) < 1LL * (x2 + l - x1) * w;
}

int main() {
    scanf("%d%d%d", &n, &l, &w);
    for(int i = 1; i <= n; i++) {
        int x, v; scanf("%d%d", &x, &v);
        if(v == 1) a.push_back(x);
        else b.push_back(x);
    }
    LL ans = 0;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(auto& x2 : b) {
        int low = 0;
        int high = lower_bound(a.begin(), a.end(), x2) - a.begin() - 1;
        int p = -1;
        while(low <= high) {
            int mid = (low + high) >> 1;
            if(check(a[mid], x2)) p = mid, low = mid + 1;
            else high = mid - 1;
        }
        ans += p + 1;
    }
    printf("%lld
", ans);
    return 0;
}

/*
*/

 

以上是关于Codeforces 989D A Shade of Moonlight的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 989D

D. A Shade of Moonlight

Codeforces 486D Valid Sets:Tree dpn遍O(n)的dp

Codeforces Round #234A

CodeForces 796A Buying A House

Codeforces 731F Video Cards