D. Virtuous Pope

 Problem - D - Codeforces

 题意为在三维空间中有多条线段,其端点在给定的长方体上,求与坐标轴垂直的平面最多能和多

少线段相交。

以与x轴垂直的平面为例(y,z轴同理),对于一个线段能被平面切断时,平面位于x1与x2之间。

由此问题转化为给定n条线段,求最多有多少线段覆盖同一位置。

考虑差分,求前缀和即可

因为n<=1e5,a,c,b <=1e9,所以要将线段离散化。

AC代码

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

struct pa {
    int l, r;
};

int findi(int x, vector<int>& a) {
    int l = -1, r = a.size();
    while (l + 1 < r) {
        int mid = l + ((r - l) >> 1);
        if (a[mid] >= x)r = mid;
        else l = mid;
    }
    return r + 1;
}
const int N = 3e5;

void solve()
{
    int n, a1, b1, c1;
    cin >> n >> a1 >> b1 >> c1;
    int x1, y1, z1, x2, y2, z2;
    // vector<int>a(a1 + 3);
    // vector<int>b(b1 + 3);
    // vector<int>c(c1 + 3);
    vector<pa>a, b, c;
    vector<int>ita, itb, itc;
    int ina[N] = { 0 }, inb[N] = { 0 }, inc[N] = {0};
    //vector<int>ina(n+1), inb(n+1), inc(n+1);//差分数组
    for (int i = 0; i < n; i++) {
        cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
        if (x1 > x2) swap(x1, x2);
        if (y1 > y2) swap(y1, y2);
        if (z1 > z2) swap(z1, z2);
        ita.push_back(x1), ita.push_back(x2);
        itb.push_back(y1), itb.push_back(y2);
        itc.push_back(z1), itc.push_back(z2);
        // a[x1]++, a[x2 + 1]--;
        // b[y1]++, b[y2 + 1]--;
        // c[z1]++, c[z2 + 1]--;
        a.push_back({ x1,x2 });
        b.push_back({ y1,y2 });
        c.push_back({ z1,z2 });
    }
    sort(ita.begin(), ita.end());
    sort(itb.begin(), itb.end());
    sort(itc.begin(), itc.end());
    ita.erase(unique(ita.begin(), ita.end()), ita.end());
    itb.erase(unique(itb.begin(), itb.end()), itb.end());
    itc.erase(unique(itc.begin(), itc.end()), itc.end());
    for (auto it : a) {
        int x = findi(it.l, ita);
        int y = findi(it.r, ita);
        ina[x]++, ina[y + 1]--;
    }
    for (auto it : b) {
        int x = findi(it.l, itb);
        int y = findi(it.r, itb);
        inb[x]++, inb[y + 1]--;
    }
    for (auto it : c) {
        int x = findi(it.l, itc);
        int y = findi(it.r, itc);
        inc[x]++, inc[y + 1]--;
    }
    int sum = 0;
    for (int i = 1; i <= ita.size(); i++) {
        ina[i] += ina[i - 1];
        sum = max(sum, ina[i]);
    }
    for (int i = 1; i <= itb.size(); i++) {
        inb[i] += inb[i - 1];
        sum = max(sum, inb[i]);
    }
    for (int i = 1; i <= itc.size(); i++) {
        inc[i] += inc[i - 1];
        sum = max(sum, inc[i]);
    }
    cout << sum;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    // cin>>t;
    while (t--) solve();
    return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值