Problem G. Pot!!(线段树银川现场赛)

Little Q is very sleepy, and he really needs some impenetrable hard problems coffee to make him awake.
At this time, Little L brings a pot to Little Q, and he states the pot as follows.
For a prime number p, if p m |n and p m+1 6 |n, we say pot p (n) = m.
The pot is very special that it can make everyone awake immediately.
Now Little L provides n (1 ≤ n ≤ 10 5 ) integers a 1 ,a 2 ,··· ,a n to Little Q, each of which is 1 initially.
After that, Little L shows 2 types of queries:
• MULTIPLY l r x : For every i ∈ [l,r] (1 ≤ l ≤ r ≤ n), multiply a i by x (2 ≤ x ≤ 10).
• MAX l r : Calculate the value of
max
l≤i≤r
?
max
p|a i
? pot
p (a i )
? ?
(1 ≤ l ≤ r ≤ n),
where p is prime.
Now you need to perform q (1 ≤ q ≤ 10 5 ) queries of these two types of queries described above.
If you perform a “MULTIPLY” query, you don’t need to output anything.
If you perform a “MAX” query, you need to output a line like “ANSWER y”, where y the value you’ve
calculated.
Input
The first line contains two integers n (1 ≤ n ≤ 10 5 ) and q (1 ≤ q ≤ 10 5 ), the number of integers and the
number of queries.
Each of the next q lines contains one type of query described above.
Output
For each “MAX” query, output one line in the format of “ANSWER y”, where y the value you have calculated.
Example
standard input standard output
5 6
MULTIPLY 3 5 2
MULTIPLY 2 5 3
MAX 1 5
MULTIPLY 1 4 2
MULTIPLY 2 5 5
MAX 3 5
ANSWER 1
ANSWER 2
Note
If m and n are non-zero integers, or more generally, non-zero elements of an integral domain, it is said
that m divides n if there exists an integer k, or an element k of the integral domain, such that m×k = n,
and this is written as m | n.
想了想还是纪念一下这道题吧。毕竟是在现场赛敲的线段树。
其实这道题目我们读懂,队友读的题意。给我说了说之后,我就想到用线段树维护四个值,因为四个值不多,4nlogn完全可以。类似于今年蓝桥国赛的一道题目。但是wa了两发,query函数写错了。日。这道题目就是线段树的基本的区间更新区间求最值。但是不是修改一个值,而是修改四个值。(没有提交试验所以不一定对。。)
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=1e5+100;
struct node{
	int l;
	int r;
	int max5,max2,max3,max7;
	int lazy5,lazy2,lazy3,lazy7;
	int _max;
}p[maxx<<2];
int n,m;

inline void pushdown(int cur)
{
	if(p[cur].lazy2)
	{
		p[cur<<1].lazy2+=p[cur].lazy2;
		p[cur<<1|1].lazy2+=p[cur].lazy2;
		p[cur<<1].max2+=p[cur].lazy2;
		p[cur<<1|1].max2+=p[cur].lazy2;
	}
	if(p[cur].lazy3)
	{
		p[cur<<1].lazy3+=p[cur].lazy3;
		p[cur<<1|1].lazy3+=p[cur].lazy3;
		p[cur<<1].max3+=p[cur].lazy3;
		p[cur<<1|1].max3+=p[cur].lazy3;
	}
	if(p[cur].lazy5)
	{
		p[cur<<1].lazy5+=p[cur].lazy5;
		p[cur<<1|1].lazy5+=p[cur].lazy5;
		p[cur<<1].max5+=p[cur].lazy5;
		p[cur<<1|1].max5+=p[cur].lazy5;
	}
	if(p[cur].lazy7)
	{
		p[cur<<1].lazy7+=p[cur].lazy7;
		p[cur<<1|1].lazy7+=p[cur].lazy7;
		p[cur<<1].max7+=p[cur].lazy7;
		p[cur<<1|1].max7+=p[cur].lazy7;
	}
	p[cur<<1]._max=max(max(p[cur<<1].max2,p[cur<<1].max3),max(p[cur<<1].max5,p[cur<<1].max7));
	p[cur<<1|1]._max=max(max(p[cur<<1|1].max2,p[cur<<1|1].max3),max(p[cur<<1|1].max5,p[cur<<1|1].max7));
	p[cur].lazy2=p[cur].lazy3=p[cur].lazy5=p[cur].lazy7=0;
}
inline void pushup(int cur)
{
	p[cur].max3=max(p[cur<<1].max3,p[cur<<1|1].max3);
	p[cur].max2=max(p[cur<<1].max2,p[cur<<1|1].max2);
	p[cur].max5=max(p[cur<<1].max5,p[cur<<1|1].max5);
	p[cur].max7=max(p[cur<<1].max7,p[cur<<1|1].max7);
	p[cur]._max=max(max(p[cur].max2,p[cur].max3),max(p[cur].max5,p[cur].max7));
}
inline void build(int l,int r,int cur)
{
	p[cur].l=l;
	p[cur].r=r;
	p[cur].max7=p[cur].max2=p[cur].max3=p[cur].max5=0;
	p[cur].lazy7=p[cur].lazy2=p[cur].lazy3=p[cur].lazy5=0;
	if(l==r) return ;
	int mid=l+r>>1;
	build(l,mid,cur<<1);
	build(mid+1,r,cur<<1|1);
}
inline void update(int l,int r,int cur,int x2,int x3,int x5,int x7)
{
	int L=p[cur].l;
	int R=p[cur].r;
	if(l<=L&&R<=r)
	{
		p[cur].lazy2+=x2;
		p[cur].lazy3+=x3;
		p[cur].lazy5+=x5;
		p[cur].lazy7+=x7;
		p[cur].max2+=x2;
		p[cur].max3+=x3;
		p[cur].max5+=x5;
		p[cur].max7+=x7;
		p[cur]._max=max(max(p[cur].max2,p[cur].max3),max(p[cur].max5,p[cur].max7));
		return ;
	}
	pushdown(cur);
	int mid=L+R>>1;
	if(r<=mid) update(l,r,cur<<1,x2,x3,x5,x7);
	else if(l>mid) update(l,r,cur<<1|1,x2,x3,x5,x7);
	else
	{
		update(l,mid,cur<<1,x2,x3,x5,x7);
		update(mid+1,r,cur<<1|1,x2,x3,x5,x7);
	}
	pushup(cur);
}
inline int query(int l,int r,int cur)
{
	int L=p[cur].l;
	int R=p[cur].r;
	if(l<=L&&R<=r) return p[cur]._max;
	pushdown(cur);
	int mid=L+R>>1;
	if(r<=mid) return query(l,r,cur<<1);
	else if(l>mid) return query(l,r,cur<<1|1);
	else return max(query(l,mid,cur<<1),query(mid+1,r,cur<<1|1));
}
int main()
{
	int l,r,x;
	scanf("%d%d",&n,&m);
	build(1,n,1);
	char s[10];
	while(m--)
	{
		scanf("%s",s);
		if(s[1]=='U')
		{
			scanf("%d%d%d",&l,&r,&x);
			int x5=0,x2=0,x3=0,x7=0;//因为x是在2~10的,所以2~10的素数只有4个,2,3,5,7.将给定的数字分解为各个素数的乘积。
			if(x==2) x2++;
			else if(x==3) x3++;
			else if(x==4) x2+=2;
			else if(x==5) x5++;
			else if(x==6) x2++,x3++;
			else if(x==7) x7++;
			else if(x==8) x2+=3;
			else if(x==9) x3+=2;
			else if(x==10) x2++,x5++;
			update(l,r,1,x2,x3,x5,x7);
		}
		else 
		{
			scanf("%d%d",&l,&r);
			printf("ANSWER %d\n",query(l,r,1));
		}
	}
	return 0;
}

银川结果不好不坏,虽然都说银川水,我也没感觉出哪儿水,可能是太菜了。尽自己努力了,结果不管如何也笑着接受了。acm真的结束了!!泪目
努力加油a啊,(o)/~

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
SELECT t.id,t.order_number,t.registration_Time,t.inspect_unit,t.inspect_form,t.unit_type,t.unit_ids,t.unit_name, t.problem,t.ask_leave_ids,t.ask_leave_name,t.disposal_situation,t.catalog_id,t.street_name,t.check_street_ids,t.check_street_name, t.receive_Unit,sd.dept_name AS receive_Unit_Name FROM tb_duty_inspect_class t LEFT JOIN tb_sys_dept sd ON sd.ID = t.receive_Unit WHERE t.is_delete='0' <if test="model.unitType != null and model.unitType!='' "> AND t.unit_type = #{model.unitType} </if> <if test="model.inspectForm != null and model.inspectForm!='' "> AND t.inspect_form like '%'||#{model.inspectForm}||'%' </if> <if test="model.disposalSituation != null and model.disposalSituation!='' "> AND t.disposal_situation like '%'||#{model.disposalSituation}||'%' </if> <if test="model.beginTime != null and model.beginTime!='' "> and to_char(t.registration_Time, 'yyyy-MM-dd')>=#{model.beginTime} </if> <if test="model.endTime != null and model.endTime!='' "> AND to_char(t.registration_Time,'yyyy-MM-dd')<=#{model.endTime} </if> <if test="model.unitName != null and model.unitName!='' "> AND t.unit_name like '%'|| #{receiveUnitName}||'%' </if> <if test="model.checkStreetName != null and model.checkStreetName!='' "> AND t.check_street_name like '%'|| #{receiveUnitName} ||'%' </if> <if test="model.inspectUnit != null and model.inspectUnit!='' "> AND t.inspect_unit = #{model.inspectUnit} </if> <if test="key == null or key == ''"> ORDER BY t.id DESC </if> <if test="key != null and key != ''"> ORDER BY ${key} ${order} </if>中我该怎么使用获取到的receive_Unit 查询出我保存unit_name
最新发布
06-01
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值