luogu P4145 上帝造题的七分钟2 / 花神游历各国 维护区间和&&区间开根号
因为开根号能使数字减小得非常快

所以开不了几次(6次?)很大的数就会变成1.....
所以我们可以维护区间最大值,若最大值>1,则继续递归子树,暴力修改叶节点,否则直接return
(好像也可以维护区间被开方的次数,但我不会。。。QAQ)
#include<cstdio>
#include<iostream>
#include<cmath>
#define int long long
#define R register int
#define ls (tr<<1)
#define rs (tr<<1|1)
using namespace std;
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
int n,m;
int mx[],sum[];
inline void build(int tr,int l,int r){
if(l==r) {mx[tr]=sum[tr]=g(); return ;}
R md=(l+r)>>;
build(ls,l,md),build(rs,md+,r);
mx[tr]=max(mx[ls],mx[rs]);
sum[tr]=sum[ls]+sum[rs];
}
inline void calc(int tr,int l,int r,int ll,int rr) {
if(mx[tr]<=) return ;
if(l==r) {mx[tr]=sqrt(mx[tr]),sum[tr]=sqrt(sum[tr]); return ;}
R md=(l+r)>>;
if(ll>md) calc(rs,md+,r,ll,rr);
else if(rr<md+) calc(ls,l,md,ll,rr);
else calc(ls,l,md,ll,md),calc(rs,md+,r,md+,rr);
mx[tr]=max(mx[ls],mx[rs]);
sum[tr]=sum[ls]+sum[rs];
}
inline int query(int tr,int l,int r,int ll,int rr) {
if(l==ll&&r==rr) return sum[tr];
R md=(l+r)>>;
if(ll>md) return query(rs,md+,r,ll,rr);
else if(rr<md+) return query(ls,l,md,ll,rr);
else return query(ls,l,md,ll,md)+query(rs,md+,r,md+,rr);
}
signed main() {
n=g(); build(,,n); m=g();
for(R i=,k,l,r;i<=m;++i) {
k=g(),l=g(),r=g();
if(l>r) swap(l,r);
if(k&) printf("%lld\n",query(,,n,l,r));
else calc(,,n,l,r);
}
}
upd 2019.06.15
可以用树状数组做,如果这个数已经为$1$就用并查集合并到上一个位置,对于没有被开成$1$的直接暴力开根。。
跑的飞快
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define ull unsigned long long
#define ll long long
#define R register ll
#define pause (for(R i=1;i<=10000000000;++i))
#define OUT freopen("out.out","w",stdout);
using namespace std;
namespace Fread {
static char B[<<],*S=B,*D=B;
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
inline ll g() {
R ret=,fix=; register char ch; whaile(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return ch<=||ch>=;}
inline void gs(char* s) {register char ch; while(isempty(ch=getchar())); do *s++=ch; while(!isempty(ch=getchar()));}
}using Fread::g; using Fread::gs;
const int N=; int n,m,fa[N];
ll c[N],h[N]; bool flg[N];
inline int lbt(int x) {return x&-x;}
inline void change(int pos) { R tmp=h[pos];
h[pos]=sqrt(h[pos]); R d=tmp-h[pos];
if(h[pos]==) flg[pos]=true;
for(;pos<=n;pos+=lbt(pos)) c[pos]-=d;
}
inline ll query(int pos) { R ret=;
for(;pos;pos-=lbt(pos)) ret+=c[pos]; return ret;
}
inline int getf(int x) {return (!flg[fa[x]])?fa[x]:fa[x]=getf(fa[x]);}
signed main() {
n=g(); for(R i=;i<=n;++i) h[i]=c[i]=g(); for(R i=;i<=n;++i) fa[i]=i-;
for(R i=;i<=n;++i) if(i+lbt(i)<=n) c[i+lbt(i)]+=c[i];
m=g(); for(R i=,x,l,r;i<=m;++i) { x=g(),l=g(),r=g(); l>r?swap(l,r):void();
if(x&) printf("%lld\n",query(r)-query(l-));
else for(flg[r]?r=getf(r):;r>=l;r=getf(r)) change(r);
}
}
2019.04.11&&2019.06.15
luogu P4145 上帝造题的七分钟2 / 花神游历各国 维护区间和&&区间开根号的更多相关文章
- 【题解】 Luogu P4145 上帝造题的七分钟2 / 花神游历各国
原题传送门 这道题实际和GSS4是一样的,只是输入方式有点区别 GSS4传送门 这道题暴力就能过qaq(这里暴力指线段树) 数据比较水 开方修改在线段树中枚举叶节点sqrt 查询区间和线段树基本操作 ...
- [Luogu P4145] 上帝造题的七分钟2 / 花神游历各国
题目链接 题目简要:我们需要一个能支持区间内每一个数开方以及区间求和的数据结构. 解题思路:说道区间修改区间查询,第一个想到的当然就是分块线段树.数据范围要用long long.本来我是看到区间这两个 ...
- P4145 上帝造题的七分钟2 / 花神游历各国(线段树区间开平方)
有点意思,不需要什么懒标记之类的东西,因为一个数无论怎样开平方,最后取整的结果必然会是1,所以我们不妨用最大值来维护,若区间最大值不为1,就暴力修改,否则不用管. #include<bits/s ...
- 洛谷P4145 上帝造题的七分钟2/花神游历各国 [树状数组,并查集]
题目传送门 题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是 ...
- 洛谷P4145——上帝造题的七分钟2 / 花神游历各国
题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是便有了对一段 ...
- 洛谷P4145 上帝造题的七分钟2 / 花神游历各国(重题:洛谷SP2713 GSS4 - Can you answer these queries IV)
题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是便有了对一段 ...
- 洛谷 P4145 上帝造题的七分钟2 / 花神游历各国
洛谷 这题就是区间开根号,区间求和.我们可以分块做. 我们记布尔数组vis[i]表示第i块中元素是否全部为1. 因为显然当一个块中元素全部为1时,并不需要对它进行根号操作. 我们每个块暴力开根号,因为 ...
- P4145 上帝造题的七分钟2 / 花神游历各国
思路 每个数不会被开方超过log次,对每个数暴力开方即可 代码 #include <algorithm> #include <cstring> #include <cst ...
- day1 晚上 P4145 上帝造题的七分钟2 / 花神游历各国 线段树
#include<iostream> #include<cstdio> #include<cmath> using namespace std; ; struct ...
随机推荐
- 时尚设计div+css免费模板
时尚设计div+css免费网页模板,时尚设计,div+css. http://www.huiyi8.com/moban/
- js正则表达式(2)
找到以某个字符串开头的字符串 var myReg=/^(abc)/gim; 如果不加m,那么只找一行,而加了m可以找到每行中以该字符串开头的匹配文本. 如: abcsfsdfasd7890hklfah ...
- 查 101.201.62.30 IP信誉方法
查 101.201.62.30 IP信誉方法https://www.virustotal.com/#/ip-address/101.201.62.30https://talosintelligence ...
- listen 80
Facebook Quietly Created New Email Addresses For a company that made its name by building one of the ...
- Vue 中数据流组件
好久不见呀,这两年写了很多很多东西,也学到很多很多东西,没有时常分享是因为大多都是我独自思考.明年我想出去与更多的大神交流,再修筑自己构建的内容. 有时候我会想:我们遇到的问题,碰到的界限,是别人给的 ...
- 【Lintcode】036.Reverse Linked List II
题目: Reverse a linked list from position m to n. Given m, n satisfy the following condition: 1 ≤ m ≤ ...
- python json ajax django四星聚会
什么是json: JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programm ...
- 【转】unittest执行测试用例的N种姿势总结
原文地址:https://www.cnblogs.com/fighter007/p/9514453.html 1.我们写几个方法,用来做测试用例 2.我们在另一文件中引用这个模块下面的所有类方法,先看 ...
- 开源.Net项目合集
http://www.cnblogs.com/StrangeCity/p/OpenSourceProject.html
- 通过bed文件获取fasta序列
一.BED 文件格式 BED 文件格式提供了一种灵活的方式来定义的数据行,以用来描述注释的信息.BED行有3个必须的列和9个额外可选的列. 每行的数据格式要求一致. 必须包含的3列: 1.chrom, ...