zoukankan      html  css  js  c++  java
  • Codeforces 924D Contact ATC (看题解)

    Contact ATC

    我跑去列方程, 然后就gg了。。。

    我们计每个飞机最早到达时间为L[ i ], 最晚到达时间为R[ i ], 

    对于面对面飞行的一对飞机, 只要他们的时间有交集则必定满足条件。

    对于相同方向飞行的飞机, 只有其中一个的时间包含另一个的时间才满足条件。

    #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 = 2e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    const double eps = 1e-8;
    const double PI = acos(-1);
    
    struct Bit {
        int a[N];
        void init() {
            memset(a, 0, sizeof(a));
        }
        void modify(int x, int v) {
            for(int i = x; i < N; i += i & -i)
                a[i] += v;
        }
        int sum(int x) {
            int ans = 0;
            for(int i = x; i; i -= i & -i)
                ans += a[i];
            return ans;
        }
        int query(int L, int R) {
            if(L > R) return 0;
            return sum(R) - sum(L - 1);
        }
    };
    
    struct Node {
        Node(LL a, LL b) : a(a), b(b) {}
        bool operator < (const Node& rhs) const {
            return a * rhs.b < rhs.a * b;
        }
        bool operator == (const Node& rhs) const {
            return a * rhs.b == rhs.a * b;
        }
        void print() {
            printf("%.5f ", 1.0 * a / b);
        }
        LL a, b;
    };
    
    int n, w, x[N], v[N];
    LL ans = 0;
    vector<PII> vc[2];
    vector<Node> hs;
    Bit bit;
    
    bool cmp(PII& a, PII& b) {
        if(a.fi == b.fi) return a.se < b.se;
        return a.fi > b.fi;
    }
    
    LL solve(vector<PII>& vc) {
        bit.init();
        LL ans = 0;
        sort(vc.begin(), vc.end(), cmp);
        for(int i = 0; i < SZ(vc); i++) {
            ans += bit.sum(vc[i].se);
            bit.modify(vc[i].se, 1);
        }
        return ans;
    }
    
    int main() {
        scanf("%d%d", &n, &w);
        for(int i = 1; i <= n; i++) {
            scanf("%d%d", &x[i], &v[i]);
            if(x[i] < 0) {
                hs.push_back(Node(-x[i], v[i] + w));
                hs.push_back(Node(-x[i], v[i] - w));
            } else {
                hs.push_back(Node(x[i], w - v[i]));
                hs.push_back(Node(x[i], -w - v[i]));
            }
        }
        sort(hs.begin(), hs.end());
        hs.erase(unique(hs.begin(), hs.end()), hs.end());
        for(int i = 1; i <= n; i++) {
            if(x[i] < 0) {
                int L = lower_bound(hs.begin(), hs.end(), Node(-x[i], v[i] + w)) - hs.begin() + 1;
                int R = lower_bound(hs.begin(), hs.end(), Node(-x[i], v[i] - w)) - hs.begin() + 1;
                vc[0].push_back(mk(L, R));
            } else {
                int L = lower_bound(hs.begin(), hs.end(), Node(x[i], w - v[i])) - hs.begin() + 1;
                int R = lower_bound(hs.begin(), hs.end(), Node(x[i], -w - v[i])) - hs.begin() + 1;
                vc[1].push_back(mk(L, R));
            }
        }
        ans += solve(vc[0]);
        ans += solve(vc[1]);
        ans += 1ll * SZ(vc[0]) * SZ(vc[1]);
        bit.init();
        for(auto& t : vc[1]) bit.modify(t.se, 1);
        for(auto& t : vc[0]) ans -= bit.sum(t.fi - 1);
        bit.init();
        for(auto& t : vc[1]) bit.modify(t.fi, 1);
        for(auto& t : vc[0]) ans -= bit.query(t.se + 1, N - 1);
        printf("%lld
    ", ans);
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    Asp.NET 4.0 ajax实例DataView 模板编程1
    ASP.NET 4.0 Ajax 实例DataView模板编程 DEMO 下载
    部分东北话、北京话
    .NET 培训课程解析(一)
    ASP.NET 4.0 Ajax 实例DataView模板编程2
    ASP.NET Web Game 架构设计1服务器基本结构
    ASP.NET Web Game 构架设计2数据库设计
    TFS2008 基本安装
    Linux上Oracle 11g安装步骤图解
    plsql developer远程连接oracle数据库
  • 原文地址:https://www.cnblogs.com/CJLHY/p/10486254.html
Copyright © 2011-2022 走看看