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 ...
随机推荐
- Python程序设计8——网络编程
Python是一个很强大的网络编程工具,python内有很多针对场景网络协议的库,在库顶部可以获得抽象层,这样就可以集中精力在程序的逻辑处理上,而不是停留在网络实现的细节中. 1 少数几个网络设计模块 ...
- 原型模式--其实就是考察clone
http://blog.csdn.net/zhengzhb/article/details/7393528
- c#继承、多重继承
c#类 1.c#类的继承 在现有类(基类.父类)上建立新类(派生类.子类)的处理过程称为继承.派生类能自动获得基类的除了构造函数和析构函数以外的所有成员,可以在派生类中添加新的属性和方法扩展其功能.继 ...
- Xamarin.Forms(一) 学习笔记
Xamarin.Forms是Xamarin跨平台开发app的跨平台的一个Framework,要使用这套Framework,要从XAML说起. XAML是同通过xml的方式来描述控件和动作,可以通过编译 ...
- C#提取TXT文档指定内容
早上有分享一篇<VB.NET提取TXT文档指定内容> http://www.cnblogs.com/insus/p/3267347.html 那是原网友的需求用VB.NET写的.刚才有只懂 ...
- git常用命令(转)
git常用命令: git init //初始化本地git环境 git clone XXX//克隆一份代码到本地仓库 git pull //把远程库的代码更新到工作台 git pull --rebase ...
- Python3中装饰器的使用
较为复杂的装饰器使用: user,passwd = 'hjc',111111 def auth(type): print('auth type:',type) def outwrapper(func) ...
- eclipse - 链接hadoop
插件: 配置:Map/Reduce Location 问题:An internal error occurred during: "Map/Reduce location status up ...
- new types may not be defined in a return type(c++语言编译错误,处理)
在写程序的时候,定义类时要在大括号后面加上: class Point{ public: Point(int a,int b); Point(const Point &p); int getx( ...
- ASP.NET-GridView之固定表数据滚动
有时候,在线Web开发时,需要显示的数据往往会超过我们规定的表格长度,所以为了方便显示大量数据,为了美观,这里提出了两种显示数据方式. ①可以滚动显示数据但是表头未能获取 效果显示 前端DEMO &l ...