Naive Operations
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315
学习博客:https://blog.csdn.net/SunMoonVocano/article/details/81207676
Naive Operations
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Others)
Total Submission(s): 4002 Accepted Submission(s): 1773
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar
2. query l r: query ∑ri=l⌊ai/bi⌋
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.
1≤n,q≤100000, 1≤l≤r≤n, there're no more than 5 test cases.
1 5 2 4 3
add 1 4
query 1 4
add 2 5
query 2 5
add 3 5
query 1 5
add 2 4
query 1 4
add 2 5
query 2 5
add 2 2
query 1 5
1
2
4
4
6
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
#include<cstring>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+;
const int maxm=+;
ll b[maxn<<];//b数组
ll lazy[maxn<<];//延迟标记
ll sum[maxn<<];//记录区间ai/bi的和
ll mi[maxn<<];//记录b数组区间最小值
ll ans=;
void Pushup(ll rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
mi[rt]=min(mi[rt<<],mi[rt<<|]);//存区间最小的值
}
void Build(ll l,ll r,ll rt)
{
if(l==r)
{
mi[rt]=b[l];
//cout<<"rt:"<<rt<<"mi:"<<mi[rt]<<endl;
return ;
}
ll mid=(l+r)>>;
Build(l,mid,rt<<);
Build(mid+,r,rt<<|);
Pushup(rt);
}
void Pushdown(ll rt)
{
mi[rt<<]-=lazy[rt];
mi[rt<<|]-=lazy[rt];
lazy[rt<<]+=lazy[rt];
lazy[rt<<|]+=lazy[rt];
lazy[rt]=;
}
void Updata(ll l ,ll r,ll rt,ll L,ll R)//(1,n,1,l,r)
{
//cout<<"*"<<"l:"<<l<<"r:"<<r<<"L:"<<L<<"R:"<<R<<"mi:"<<mi[rt]<<"rt:"<<rt<<endl;
if(L<=l&&r<=R)//这里是重点
{
// cout<<"叶子rt:"<<rt<<endl;
if(mi[rt]>)//最小的都大于1,那么整个区间ai/bi肯定是没有影响的,
{
mi[rt]--;
lazy[rt]++;
return ;
}
} if(l==r)//到了叶子节点,代表mi[rt]<=1 此时sum值要加1,同时mi[rt]恢复原值
{
sum[rt]++;
mi[rt]=b[l];
return ;
}
if(lazy[rt])
Pushdown(rt);
ll mid=(l+r)>>; if(L<=mid) Updata(l,mid,rt<<,L,R);
if(R>mid) Updata(mid+,r,rt<<|,L,R); Pushup(rt);
}
void Query(ll l,ll r,ll rt,ll L,ll R)
{
if(L<=l&&r<=R)
{
ans+=sum[rt];
return ;
}
ll mid=(l+r)>>; if(lazy[rt])
Pushdown(rt); if(L<=mid) Query(l,mid,rt<<,L,R);//就是这里卡了几个小时 我把l写成1了 !!! 一直re 找了很久。。。
if(R>mid) Query(mid+,r,rt<<|,L,R); }
int main()
{
ll n,q;
ll l,r;
//string s;
char s[];
//while(cin>>n>>q)
while(scanf("%lld%lld",&n,&q)!=EOF)//cin cout会超时
{
ans=;
memset(sum,,sizeof(sum));
memset(lazy,,sizeof(lazy));
memset(mi,,sizeof(mi));
for(int i=;i<=n;i++) scanf("%d",&b[i]);
//cin>>b[i];
Build(,n,);
for(int i=;i<=q;i++)
{
ans=;
scanf("%s%lld%lld",s,&l,&r);
//cin>>s>>l>>r;
if(s[]=='a')
{
Updata(,n,,l,r); }
else
{
Query(,n,,l,r);
printf("%lld\n",ans);
//cout<<ans<<endl;
}
}
}
return ;
}
Naive Operations的更多相关文章
- HDU 6351 Naive Operations(线段树)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/O ...
- hdu 6315 Naive Operations (2018 Multi-University Training Contest 2 1007)
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- hdu Naive Operations 线段树
题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...
- HDU-6315:Naive Operations(线段树+思维)
链接:HDU-6315:Naive Operations 题意: In a galaxy far, far away, there are two integer sequence a and b o ...
- HDU 多校对抗 F Naive Operations
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU 6315: Naive Operations
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU6315 Naive Operations(多校第二场1007)(线段树)
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU-6315 Naive Operations//2018 Multi-University Training Contest 2___1007 (线段树,区间除法)
原题地址 Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/ ...
- 杭电多校第二场 hdu 6315 Naive Operations 线段树变形
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
随机推荐
- 《Maven实战》笔记-4-生命周期和插件
除了坐标.依赖以及仓库外,Maven另外两个核心概念是生命周期和插件. 一.生命周期 Maven的生命周期是抽象的,其本身不做任务实际的工作,实际的任务(如编译源代码)都交由插件来完成. 三套生命周期 ...
- 《Spring实战》-2
装配Bean 1.装配wiring,即创建应用对象之间的协作关系的行为,者也是依赖注入的本质. 2.创建Spring配置 从Sring3.0开始,Spring容器提供了两种配置Bean的方式: XML ...
- Visual Studio 2012自动添加注释(如版权信息等)
http://blog.csdn.net/jiejiaozhufu/article/details/16357721注释宏的原码 /********************************** ...
- python(二):可变参数
python中的函数定义: def func(参数, 默认参数, 可变参数) ... 可变参数有两种定义方式: def func(*args): ... 调用方式为func(arg1, arg2, a ...
- 对Dapper的一点改造
微软推出的ORM, EF在我开发的项目中给我的感觉一直都是慢.优点是高度封装的底层.便于开发. Dapper在多篇性能比较的网站中.都是名列前三.缺点是手写SQL,不便于开发. 如果能结合EF的优 ...
- 根据某条件给GridView符合条件的值画上删除线
如博文标题,根据某些条件对GridView控件中,对符合条件的值画上删除线效果.实现这些要求,只人捕获到哪些符合要求的数据即可.GridView控件是在TemplateField模版显示数据,Insu ...
- tomcat启动后 项目运行缓慢,要几十到几百秒不等 怎么样./startup.sh 运行加快
修改 linux系统中 /usr/local/jdk1.8.0_11/jre/lib/security/java.security 借力 好文章.我们新的Linux系统,部署了多个 Tomca,同时重 ...
- Angular2入门-架构总览
▓▓▓▓▓▓ 大致介绍 在3月23日,Angular4正式发布(没有3).似乎现在学Angular2又晚了,又晚一步-_-||.Angular2在Angular1的基础上有了较大的改变.之前向一个同学 ...
- Windows Server 2016 IIS10安装URLRewrite 2.0组件方法
1,打开Regedit> HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ InetStp2,编辑“MajorVersion”并以十进制设置数值数据值为93 ...
- 《图解HTTP》阅读笔记--第六章--HTTP首部
第六章.HTTP首部 <非常重要且恐怖的一章了> HTTP报文=报文首部+(CR+LF)+报文实体 首部字段:HTTP报文首部字段=(首部字段名:字段值)们---类型*4: 通用首部字段( ...