HDOJ 4638 Group

从零构建OpenBMC风扇控制:基于phosphor-pid-control的实战配置指南 本文详细介绍了如何从零开始构建OpenBMC风扇控制系统,基于phosphor-pid-control框架实现风扇自动调速。通过解析PID算法配置、传感器定义及控制区域设置,提供工业级散热解决方案,帮助开发者优化服务器能效与可靠性。 阅读详情

 求一段区间内有几段连续的数。。。

考虑从左开始往右扫:

对于数a 如果a+1和a-1都没有那么区间段数加1;如果a+1或a-1中的一个已经在被扫过了,那么区间段数没有增加;

如果a+1和a-1都在,正好把两个数连起来区间段数-1。。

变化总和就是。。。最终的段数。

将询问离线按L排序处理,删除数a的时候,如果与a相邻的数还在后面,那么对应的变化值+1。。。。

数状数组维护即可


Group

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1183    Accepted Submission(s): 637


Problem Description
There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-1 are friends, Whose ID is i and i+1 are friends. These n men stand in line. Now we select an interval of men to make some group. K men in a group can create K*K value. The value of an interval is sum of these value of groups.  The people of same group's id must be continuous. Now we chose an interval of men and want to know there should be how many groups so the value of interval is max.
 

Input
First line is T indicate the case number.
For each case first line is n, m(1<=n ,m<=100000) indicate there are n men and m query.
Then a line have n number indicate the ID of men from left to right.
Next m line each line has two number L,R(1<=L<=R<=n),mean we want to know the answer of [L,R].
 

Output
For every query output a number indicate there should be how many group so that the sum of value is max.
 

Sample Input
  
1 5 2 3 1 2 5 4 1 5 2 4
 

Sample Output
  
1 2
 

Source
 


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;

const int maxn=110000;

int n,m,a[maxn],tr[maxn],ans[maxn],ntop[maxn];

struct Question
{
	int L,R,id;
}Q[maxn];

bool cmp(Question a,Question b)
{
	if(a.L!=b.L) return a.L<b.L;
	return a.R<b.R;
}

int lowbit(int x)
{
	return x&(-x);
}

void ADD(int p,int v)
{
	for(int i=p;i<maxn;i+=lowbit(i))
		tr[i]+=v;
}

int SUM(int p)
{
	int sum=0;
	for(int i=p;i;i-=lowbit(i))
		sum+=tr[i];
	return sum;
}

int main()
{
	int T_T;
	scanf("%d",&T_T);
	while(T_T--)
	{
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++) 
		{
			scanf("%d",a+i);
			ntop[a[i]]=i;
		}
		for(int i=0;i<m;i++)
		{
			Q[i].id=i;
			scanf("%d%d",&Q[i].L,&Q[i].R);
		}
		sort(Q,Q+m,cmp);
		memset(tr,0,sizeof(tr));
		set<int> st;
		///一遍扫过去
		for(int i=1;i<=n;i++)	
		{
			int temp=0,left=st.count(a[i]-1),right=st.count(a[i]+1);
			st.insert(a[i]);
			if(left&&right) temp=-1;
			if(left==0&&right==0) temp=1;
			ADD(i,temp);
		}
		int cur=1;
		for(int i=0;i<m;i++)
		{
			while(cur<Q[i].L)
			{
				if(st.count(a[cur]-1))	ADD(ntop[a[cur]-1],1);
				if(st.count(a[cur]+1))  ADD(ntop[a[cur]+1],1);
				st.erase(a[cur]);
				cur++;
			}
			ans[Q[i].id]=SUM(Q[i].R)-SUM(Q[i].L-1);
		}
		for(int i=0;i<m;i++) printf("%d\n",ans[i]);
	}
	return 0;
}




openEuler 22.03 安装及配置Gitlab容器 在 openEuler 22.03 上安装及配置Gitlab容器 阅读详情

相关推荐

SAP_SD模块更改销售订单定价简介

方式优点缺点适用场景MASS简单,无需开发不能触发重新定价逻辑修改特定字段BDC (VA02)可模拟人工操作维护复杂,速度慢少量订单批改稳定、安全需ABAP支持推荐用于批量重新定价VBOF标准重算返利仅适返利类条件返利更新通过本文,我们了解了 SAP 的[SAP_SD模块更改销售订单定价]的基本概念和应用方法。希望这些信息能帮助您在实际工作中更好地使用 SAP 系统,提高工作效率和管理水平。更多SAP文章请点击更多SAP文章更新,大家一起学习进步!!!

我小时候很黑的博客 628

HDU4638:Group(线段树离线处理)

Problem Description There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-1 are friends, Whose ID is i and i+1 are friends. These n men stand in line. Now we select an

ACM!荣耀之路! 1916

TC8:IPv4_HEADER_05-09

所有主机都必须准备好接受最多576个字节的数据报我们知道最大传输单元MTU通常是1500个字节,也就是说一条IP数据报的Header+payload最大1500,那为什么这条测试用例又要求主机准备好接受最多576个字节的IP数据报呢。

jasonj333 465

HDU4267(树状数组)

题目大意:给一数列,有两种操作,一种是在[a, b]内,对(i - a) % k == 0 的所有值加上c,另一种是查询某个位置的值。 思路:由于本题k #include #include #include #include #include #include using namespace std; const int maxn = 55555; int aa[maxn]; in

phantom_kiddo的博客 548

hdu4267 线段树

这题时间卡的真紧,内存卡的更紧。。。 做这题时写了三份代码,第一份是最基础的线段树区间更新,记录更新条件,开一颗线段树记录值,一颗记录

creater_X 1377

HDOJ 4267 A Simple Problem with Integers 树状数组

建10*10个树状数组,tree[x][y]tree[x][y]表示从x开始等差为y的树状数组.对于每个询问a,统计与a相关的的数组数组的和.A Simple Problem with IntegersTime Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissio

码代码的猿猿 894

HDU 4267 经典树状数组

题目链接A Simple Problem with IntegersTime Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4005 Accepted Submission(s): 1245Problem DescriptionLet A1

ZQDNR 555

HDOJ 4638: Group

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 题目大意: 给定一个序列,是1~n的一个排列。 每次查询一个区间,问这个区间中含有多少个子集,自己中的序号是连续递增的(顺序可打乱)。 例如区间1,5,3,2可以分成1,2,3和5。 算法: 不难看出一个点只能影响两个点,也只能被两个点影响。 我们先算出每个点前面有

frog的小池塘 1196

【树状数组】 HDOJ 4638 Group

离线处理,

yysys 512

hdu 4267

题目链接为了这题学习了树状数组三维树状数组(i-a)%k==0等价于i%k==a%k,所以可以把不同位置按取K的模放到一组里ar[x][k][mod]表示在x位置k=k时,余数为mod的值,求一个位置的值,只要遍历与v%i相等的数的和就行了  #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;algorithm&gt; us...

OuterST 937

HDU4267(2012长春网络赛)

题目:A Simple Problem with Integers   #include #include #include using namespace std; const int N = 50100; struct node { int l; int r; int w; int add[55] ; }p[N

ACdreamer 1269

HDU4638-Group (莫队模板)

There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-1 are friends, Whose ID is i and i+1 are friends. These n men stand in line. Now we select an interval of men to make

swust5120160705的博客 381

HDOJ 4267 A Simple Problem with Integers(线段树)

/* 显然这道题应该用线段树来做,区间更新、多次查找,然而线段树中状态比较多,需要用多个线段树来表示这些状态。 原来线段树中c[][]为一个二维数组,c[k][u],其中k表示余数,u表示a%k,这样共有55种情况,不过最后内存超,然后用一维表示,通过。 思路:(i - a) % k == 0 可以等效于 i % k == a % k */ #include #include const i

887

hdu(4267)A Simple Problem with Integers(三维树状数组)

这道题拿过来感觉很蒙 , 因为以前做的都是点更新询问区间 , 或是区间更新询问点 , 这道题是在[a,b]区间内隔k个数更新一次( (i - a) % k == 0即i%k==a%k),  对于树状数组来说按照一维的方式定义, 后面在加上两维  c[i][k][i%k]  (a #include #include #include string> #include string.h

Roly 524

HDU 4638--莫队算法

http://acm.hdu.edu.cn/showproblem.php?pid=4638 题意1---n的排列,给定一个区间,找出一种分组方法,组最少(每组里面的数要连续)。。 这题可以预处理,离线树状数组什么的貌似。。。不过学习莫队算法,以后来填坑。。 莫队算法这里就不详细介绍,本质上就是暴力算法,需要手写add(x)和del(x),具体情况具体分析(例如这题 这题直

zxl博客 1133

HDOJ 4267 A Simple Problem with Integers

题意:维护一个整数序列,支持2种操作: 1 a b k c将区间[a b]中满足(i-a)%k==0的数加上c; 2 x查询第x个数的值。 数据范围:整数个数N<=50000,操作次数Q<=50000,1<=k<=10 分析:此题关键在于处理修改操作,我们发现修改是等间隔的,所以可以将数组拆开如下: k=1时,间隔为0: 1 2 34 5 6 7 8 9 10...

weixin_30747253的博客 137

莫队算法 HDU4638

区间问题 暴力解法+离线处理题目传送门:小Z的袜子#include <iostream> #include<cstring> #include<algorithm> #include<cmath> #include <cstdio> using namespace std; #define maxn 50010 typedef long long ll; int n,m; int a[maxn]=

ruojingzhang的博客 575

hdu4267

#include #include const int MAXN = 50005; int lowbit(int x) { return x&(-x); } int c[MAXN][11][11],n,a[MAXN]; void modi(int pos,int val,int k,int mod) { while(pos>0) { c[pos]

Code of Duty 861

hdu 4368 树状数组 离线维护

http://acm.hdu.edu.cn/showproblem.php?pid=4638 Problem Description There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-1 are friends, Whose ID is i and i+1 are f

ACM,再见! 1140

hdu 4638 Group(莫队算法)

Problem Description There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-1 are friends, Whose ID is i and i+1 are friends. These n men stand in line. Now we select an

ZAQ的博客 1703

hdu4267分组线段树

http://acm.hdu.edu.cn/showproblem.php?pid=4267 Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of operations. One type of operation is to add a give

ACM,再见! 1127

hdoj 4267 A Simple Problem with Integers 【线段树】

题目链接:hdoj 4267 A Simple Problem with Integers A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5030 Accepte

世界很大 882

DHT11温湿度传感器实验_stm32f103温度湿度传感器实验_

stm32f103读取DHT11温度湿度传感器的数据

2025河北省道路路网矢量数据图层Shp数据最新版下载

2025河北省道路路网矢量数据图层,shp格式,包含多级道路分类属性,路名等属性,包含全省几十万条道路,坐标系为WGS1984坐标系统

上一篇: HDOJ 2478 Slides
下一篇: HDOJ 4293 Groups
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值