当前位置:网站首页>Niuke hand speed monthly race 48 C (I can't understand the difference. It belongs to yes)
Niuke hand speed monthly race 48 C (I can't understand the difference. It belongs to yes)
2022-04-23 02:26:00 【Find a derivative first】
I don't want to play spicy !
It's been a long time since I hit a cow , Second question wa5 Hair , The mentality is a little fried . I don't know the penalty time when I do the questions of ladder competition every day , Just a tough man , It's a bad habit . only , Clean up and retire .
subject
The question : Given n A number from 1 To n The range of , Given len, Find how many intervals satisfy the length of len And the number of intersections with the interval is the largest and the weight is the largest .
The weight : Number and of all intersecting sections .
Ideas : Just think about it , Move only one grid at a time , Just preprocess the information . Silly , Must use vector Handle . This is very similar to the difference , But not where it disappears –, Because maybe the left end of the interval is still in the interval . Just open one more array to record the right endpoint of all given intervals , When enumerating, you can subtract .
! Note that the maximum at the right endpoint is 5e6+5e6
Time complexity : O(n)
Code :
#include<bits/stdc++.h>
using namespace std;
const int N = 1e7+10;
typedef long long ll;
int n,m,k,T;
int b[N],bb[N];
ll w[N],ww[N];
ll ans = 0;
ll mx = 0;
ll quan = 0;
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;++i)
{
int x,y; cin>>x>>y;
b[x]++,bb[y]++;
w[x]+=i,ww[y]+=i;
}
ll now;ll sum;
for(int i=1;i<=m;++i) mx += b[i],quan += w[i];ans = 1;
now = mx; sum = quan;
for(int i=m+1;i<N;++i)
{
now += b[i]; sum += w[i];
now -= bb[i-m]; sum -= ww[i-m];
if(now > mx || (now==mx&&sum>quan))
{
mx = now; quan = sum; ans = 0;}
if(now==mx&&sum==quan) ans++;
}
cout<<ans;
}
signed main(void)
{
T = 1;
// cin>>T;
while(T--)
solve();
return 0;
}
版权声明
本文为[Find a derivative first]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230222217245.html
边栏推荐
- IAR embedded development stm32f103c8t6 Lighting LED
- 013_基于Session实现短信验证码登录流程分析
- Redis memory recycling strategy
- This is how the power circuit is designed
- How to configure iptables to realize local port forwarding
- Latin goat (20204-2022) - daily question 1
- 小程序 canvas 画布半圆环
- Summary of I / O knowledge points
- Unicorn bio raised $3.2 million to turn prototype equipment used to grow meat into commercial products
- They are all intelligent in the whole house. What's the difference between aqara and homekit?
猜你喜欢
89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur
Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
How to recognize products from the perspective of Dialectics
Latin goat (20204-2022) - daily question 1
006_redis_jedis快速入门
SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
双亲委派模型【理解】
每日一题冲刺大厂第十六天 NOIP普及组 三国游戏
MySQL C language connection
随机推荐
WordPress calls the specified page content. 2 get_ children()
011_ Redistemplate operation hash
不断下沉的咖啡业,是虚假的繁荣还是破局的前夜?
A simple and open source navigation website source code
VMware virtual machine installation openwrt as side route single arm route img image to vmdk
Day18 -- stack queue
Open3d point cloud processing
2018 China Collegiate Programming Contest - Guilin Site J. stone game
Network jitter tool clumsy
Hyperscan -- 2 compilation
So library dependency
[chrome extender] content_ Cross domain problem of script
A domestic image segmentation project is heavy and open source!
006_ redis_ Jedis quick start
Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
IAR embedded development stm32f103c8t6 Lighting LED
Tp6 Alibaba cloud SMS window reports curl error 60: SSL certificate problem: unable to get local issuer certificate
Go language ⌈ mutex and state coordination ⌋
PTA: praise the crazy devil
Leetcode46 Full Permutation