【bzoj3211】花神游历各国
Description

Input

Output
每次x=1时,每行一个整数,表示这次旅行的开心度
Sample Input
1 100 5 5
5
1 1 2
2 1 2
1 1 2
2 2 3
1 1 4
Sample Output
11
11
HINT
对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9
Source
SPOJ2713 gss4 数据已加强
Solution
显然是一道线段树,开根号直接暴力就可以了,对于任意一个数最多开5次就变为1,之后就不要在开根了,打一个Tag记录一下。
type
tree=record
s,q,l,r:int64;
end;
var
n,m,k,x,y,i:longint;
f:array [..] of tree;
a:array [..] of longint;
procedure build(x,l,r:longint);
begin
f[x].l:=l;f[x].r:=r;
if l=r then
begin
f[x].s:=a[l];
if (f[x].s=) or (f[x].s=)
then f[x].q:=
else f[x].q:=;
exit;
end;
build(x<<,l,(l+r) >> );
build(x<<+,(l+r) >> +,r);
f[x].s:=f[x<<].s+f[x<<+].s;
f[x].q:=f[x<<].q and f[x<<+].q;
end; function plus(x,l,r:longint):int64;
var
mid:longint;
begin
plus:=;
if (f[x].l<=l) and (f[x].r>=r) then exit(f[x].s);
mid:=(f[x].l+f[x].r)>>;
if mid>=r
then plus:=plus+plus(x<<,l,r);
if mid<l
then plus:=plus+plus(x<<+,l,r);
if (mid>=l) and (mid<r)
then begin plus:=plus(x<<,l,r)+plus(x<<+,l,r) end;
end; procedure sq(x,l,r:longint);
var
mid:longint;
begin
if f[x].q=
then exit;
if (f[x].l=f[x].r) then
begin
f[x].s:=trunc(sqrt(f[x].s));
if (f[x].s=) or (f[x].s=)
then f[x].q:=;
exit;
end;
mid:=(f[x].l+f[x].r)>>;
if mid>=r
then sq(x<<,l,r);
if mid<l
then sq(x<<+,l,r);
if (mid>=l) and (mid<r)
then begin sq(x<<,l,r);sq(x<<+,l,r) end;
f[x].q:=f[x<<].q and f[x<<+].q;
f[x].s:=f[x<<].s+f[x<<+].s;
end; begin
read(n);
for i:= to n do
begin
read(a[i]);
end;
build(,,n);
read(m);
for i:= to m do
begin
read(k,x,y);
case k of
:writeln(plus(,x,y));
:sq(,x,y);
end;
end;
end.
【bzoj3211】花神游历各国的更多相关文章
- BZOJ3211花神游历各国
BZOJ3211花神游历各国 BZOJ luogu 分块 记一个all表示该块是否全部<=1,如果all不为真就暴力修改 因为一个数被开根的次数不多,即使\(10^{12}\)只要开根6次也会变 ...
- bzoj3211花神游历各国&&bzoj3038上帝造题的七分钟2*
bzoj3211花神游历各国 题意: n个数的序列,m个操作,操作两种:区间开根(向下取整)和区间求和.n≤100000,m≤200000,序列中的数非负且≤109. 题解: 一个≤109的数开6次根 ...
- bzoj3211 花神游历各国 线段树,势能分析
[bzoj3211]花神游历各国 2014年3月17日2,7230 Description Input Output 每次x=1时,每行一个整数,表示这次旅行的开心度 Sample Input ...
- BZOJ-3211花神游历各国 并查集+树状数组
一开始想写线段树区间开方,简单暴力下,但觉得变成复杂度稍高,懒惰了,编了个复杂度简单的 3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MB Subm ...
- bzoj3211花神游历各国 线段树
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 4252 Solved: 1547[Submit][Status][Discu ...
- BZOJ3211: 花神游历各国(线段树)
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 5692 Solved: 2114[Submit][Status][Discu ...
- [BZOJ3211]花神游历各国&&[BZOJ3038] 上帝造题的七分钟2 树状数组+并查集
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 4057 Solved: 1480[Submit][Status][Discu ...
- bzoj3211: 花神游历各国(线段树) 同codevs2492
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 3628 Solved: 1326[Submit][Status][Discu ...
- [BZOJ3211]:花神游历各国(小清新线段树)
题目传送门 题目描述: 花神喜欢步行游历各国,顺便虐爆各地竞赛.花神有一条游览路线,它是线型的,也就是说,所有游历国家呈一条线的形状排列,花神对每个国家都有一个喜欢程度(当然花神并不一定喜欢所有国家) ...
- BZOJ3211 花神游历各国 并查集 树状数组
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ3211 题意概括 有n个数形成一个序列. m次操作. 有两种,分别是: 1. 区间开根(取整) 2. ...
随机推荐
- python selenium 操作chrome
1.下载chromedriver.exe 入在chrome 浏览器目录下 from selenium import webdriverimport os chromedriver = "C: ...
- NRF51822之ADC(1)
在开始讲解的前,我们不生产水,我们只是大自然的搬运工.开始搬手册(nRF51 Series Reference Manual Version 3.0)上的资料
- 贪吃蛇游戏C语言源代码学习
源代码下载地址为:www.clang.cc 阅读学习了源代码,并做了简单的注释和修改,里面只用了链表数据结构,非常适合C语言入门者学习阅读. 程序可在VS2013下编译运行. #include< ...
- Res_Orders_02
一.燃尽图展示 二.项目进展 1.实现用户名找回 2.css样式嵌入
- C# string.Split对于换行符的分隔正确用法
C# string.Split对于换行符的分隔正确用法 tmpCase "11117144-8c91-4817-9b92-99ec2f9d784a\r\n23D95A26-012C-4332 ...
- type
MollyPages.org"You were wrong case.To live here is to live." Home Pages / Database / Forms ...
- leetcode 4. Median of Two Sorted Arrays
https://leetcode.com/problems/median-of-two-sorted-arrays/ There are two sorted arrays nums1 and num ...
- 通过属性 Cesium的FBO主要支持两种方式
角色其实就是一类权限的分组,所以给用户分配角色其实也是在给用户分配权限.在oracle中有三个比较常用的角色.对于一般不是很严格的系统可以授予开发用户CONNECT.RESOURCE角色权限即可. 其 ...
- 正确理解javascript当中的面向对象
认识面向对象: 为了说明 JavaScript 是一门彻底的面向对象的语言,首先有必要从面向对象的概念着手 , 探讨一下面向对象中的几个概念: 1.万物皆为空:万物皆对象 2.对象具有封装和继承特性 ...
- python批量处理excel文件数据
https://www.zhihu.com/question/39299070?sort=created 作者:水中柳影链接:https://www.zhihu.com/question/392990 ...