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;
}