2020CCPC秦皇岛

E
求学生那个通过率
定答案求答案
然后差分维护

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=5e5+5;
int a[maxn];
int case_=0;
vector<int>vv;
struct node
{
    int l,r;
};
node no[maxn];
void solve()
{
    vv.clear();
    int n,p;
    cin>>n>>p;
    int max_=0;
    for(int i=1;i<=n;i++)
    {
        int l,r;
        cin>>l>>r;
        no[i].l=l;
        no[i].r=r;
        if(r>max_)
            max_=r;
        vv.push_back(l);
        vv.push_back(r);
    }
    sort(vv.begin(),vv.end());
    vv.erase(unique(vv.begin(),vv.end()),vv.end());
    int st=lower_bound(vv.begin(),vv.end(),max_)-vv.begin();
    memset(a,0,sizeof(a));
    for(int i=1;i<=n;i++)
    {
        int l=no[i].l;
        int r=no[i].r;
        int A=100*l/p;
        int B=l;
        int C=100*r/p;
        int D=r;
        int AA=upper_bound(vv.begin(),vv.end(),A)-vv.begin()-1;
        int BB=upper_bound(vv.begin(),vv.end(),B)-vv.begin()-1;
        int CC=upper_bound(vv.begin(),vv.end(),C)-vv.begin()-1;
        int DD=upper_bound(vv.begin(),vv.end(),D)-vv.begin()-1;
        if(CC>=BB)
        {
            a[DD]+=1;
            a[AA+1]-=1;
        }
        else
        {
            a[DD]+=1;
            a[CC+1]-=1;
            a[BB]+=1;
            a[AA+1]-=1;
        }
    }
    int res=0;
    int sum=0;
    for(int i=0;i<vv.size();i++)
    {
        sum+=a[i];
        if(i>=st)
        {
            if(sum>res)
            {
                res=sum;
            }
        }
    }
    cout<<"Case #"<<case_<<": ";
    cout<<res<<"\n";
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int _=1;
    cin>>_;
    while(_--)
    {
        case_++;
        solve();
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值