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 ...
随机推荐
- Entity Framework Tutorial Basics(23):Add Single Entity
Add New Entity using DBContext in Disconnected Scenario: In this chapter you will learn how to add n ...
- [转]JQ中$(window).load和$(document).ready区别与执行顺序
一.$(window).load().window.onload=function(){}和$(document).ready()方法的区别 1.$(window).load() 和window.on ...
- HTML5游戏开发 PDF扫描版
很多从事Web前端开发的人对HTML总有些不满,比如需要手动检查和设计很多格式代码,不仅容易出错,而且存在大量重复.好在HTML5让我们看到了曙光.作为下一代Web开发标准,HTML5成为主流的日子已 ...
- Dev Envirenment - VS Code && C++ && MinGW
1. 安装编译器 安装 MinGW-W64 添加系统环境变量 注意: 1)安装 MinGW 的时候要选择正确的 CPU 处理器类型 2)添加系统变量后需要重启电脑系统 2. 安装本文编辑器 安装 VS ...
- 获取GridView控件总列数
GridView控件,它不管是放在MasterPage母版页内,还是放在Page单独网页内,它不管是自动显示列AutoGenerateColumns="true",还是手动定列Au ...
- Gazebo学习随记5 杂记
模拟建筑编辑器 将卫星图导入世界,方便空中机器人模拟 录像和回放 记录筛选 给关节添加力/扭矩 一开始不知道哪里出现了偏差以一动不动,重启就好了 HDF5数据集 代码内省 模型插件 !!!我终于 ...
- 9、OpenCV Python 边缘保留滤波
__author__ = "WSX" import cv2 as cv import numpy as np # 边缘保留滤波 十分重要(美颜的核心) # 高斯双边模糊(考虑到了像 ...
- P3897 [湖南集训]Crazy Rabbit
\(\color{#0066ff}{ 题目描述 }\) 兔子们决定在自己的城堡里安排一些士兵进行防守. 给出 n 个点的坐标,和城堡里一个圆心在原点的圆形的障碍,兔子们希望从中选出 k 个兔子,使得它 ...
- CF431B Shower Line
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibil ...
- 下载GitHub仓库的某个子文件夹
http://downgit.zhoudaxiaa.com/#/home