当前位置:网站首页>K gold Chef (two conditions, two points and difference)
K gold Chef (two conditions, two points and difference)
2022-06-26 14:23:00 【Honestbutter-】
link
Two points + Difference
Two point maximum ,check The solution satisfying two conditions is obtained .( What we used to do was to meet one condition , Pay attention to the difference )
Topic purpose : Make the common interval as long as possible , And the number of common intervals should be as many as possible .
We get two points each time mid, Refers to the number of people , Also refers to length .
And then the first one for The length of the circular record shall meet ≥mid Prefix and number of people , the second for The cyclic difference is consistent with ≥mid The length of the number , If the number of people sum[i]≥mid,return true,( Two conditions are met ).
#include<iostream>
#include<cstring>
using namespace std;
const int N=3e5+1000;
typedef pair<int,int> PII;
PII a[N];
int n,m,sum[N];
// Two point maximization feasible answer , For every time mid, Differential maintenance determines whether there is a continuous length not less than mid And the number of people is not less than mid The range of
bool check(int mid) // The number of ≥mid, length ≥mid
{
memset(sum,0,sizeof sum);
for(int i=0;i<m;i++)
{
int len=a[i].second-a[i].first+1;
if(len>=mid) // The first condition
{
sum[a[i].first+mid-1]++;
sum[a[i].second+1]--;
}
}
for(int i=1;i<=n;i++)
{
sum[i]+=sum[i-1];
if(sum[i]>=mid) // The second condition
return true;
}
return false;
}
int main()
{
cin>>n>>m;
for(int i=0;i<m;i++) cin>>a[i].first>>a[i].second;
int l=0,r=m-1;
while(l<r)
{
int mid=(l+r+1)/2;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
return 0;
}
边栏推荐
- 扩展-Hooks
- Linear basis
- Comparison of disk partition modes (MBR and GPT)
- Chinese output of PostGIS console is garbled
- Self created notes (unique in the whole network, continuously updated)
- Practice with the topic of bit operation force deduction
- Lucky numbers in the matrix
- 永远不要使用Redis过期监听实现定时任务!
- Design of PHP asymmetric encryption algorithm (RSA) encryption mechanism
- Mathematical design D12 according to string function
猜你喜欢

9项规定6个严禁!教育部、应急管理部联合印发《校外培训机构消防安全管理九项规定》

Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills

登录认证服务

ArcGIS batch render layer script

Knowledge about the determination coefficient R2 and the relationship with the correlation coefficient

GDAL multiband synthesis tool

Server create virtual environment run code

Gartner 2022年顶级战略技术趋势报告

hands-on-data-analysis 第三单元 模型搭建和评估

A must for programmers, an artifact utools that can improve your work efficiency n times
随机推荐
Related knowledge of libsvm support vector machine
GDAL multiband synthesis tool
How to personalize VIM editor format (DIY)
A solution to the problem that the display of newff function in neural network cannot be converted from double to struct
MySQL configuration improves data insertion efficiency
Pycharm远程连接服务器来跑代码
Flex & Bison 开始
(improved) bubble sorting and (improved) cocktail sorting
FreeFileSync 文件夹比较与同步软件
量化框架backtrader之一文读懂observer观测器
Heap optimization dijkstra/hash table storage node number
How to call self written functions in MATLAB
Research on balloon problem
A标签去掉下划线
9項規定6個嚴禁!教育部、應急管理部聯合印發《校外培訓機構消防安全管理九項規定》
ICML 2022 | limo: a new method for rapid generation of targeted molecules
Lucky numbers in the matrix
Correlation of XOR / and
idea快捷键
Codeforces Round #765 (Div. 2) D. Binary Spiders