当前位置:网站首页>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
边栏推荐
- 【无标题】
- [chrome extender] content_ Cross domain problem of script
- Redis memory recycling strategy
- PHP sorting of interview questions on April 20, 2022
- 012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
- Is the sinking coffee industry a false prosperity or the eve of a broken situation?
- 001_ Redis set survival time
- 009_ Redis_ Getting started with redistemplate
- day18--栈队列
- arduino esp8266 网络升级 OTA
猜你喜欢
随机推荐
How to call out services in idea and display the startup class in services
Go language ⌈ mutex and state coordination ⌋
全局、獨享、局部路由守衛
Real math problems in 1958 college entrance examination
我国科学家揭示突破水稻产量瓶颈新机制
Summary of I / O knowledge points
JSP page nesting
openstack 服务的启动
If 404 page is like this | daily anecdotes
PTA: Romantic reflection [binary tree reconstruction] [depth first traversal]
【ValueError: math domain error】
用TensorFlow实现线性回归(包括过程中出现的问题及解决方法)
ThinkPHP kernel development blind box mall source code v2 0 docking easy payment / Alibaba cloud SMS / qiniu cloud storage
007_Redis_Jedis连接池
006_ redis_ Jedis quick start
小程序 读取文件
Arduino esp8266 network upgrade OTA
Handwritten memory pool and principle code analysis [C language]
程序设计天梯赛 L1-49 天梯赛分配座位(模拟),布响丸辣
Want to experience homekit smart home? Why don't you take a look at this smart ecosystem








