【SP2713 GSS4 - Can you answer these queries IV】 题解
题目链接:https://www.luogu.org/problemnew/show/SP2713
真暴力啊。
开方你开就是了,开上6次就都没了。
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 100100;
inline ll read(){
ll k = 0 ; char c = getchar() ;
while (!isdigit(c)) c = getchar() ;
while (isdigit(c)) k = k * 10 + c - 48, c = getchar() ;
return k ;
}
ll n, m, a[maxn], t=0;
class Segment_Tree{
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
public:
ll tree[maxn<<2];
void build(ll l, ll r, ll rt)
{
if(l == r)
{
tree[rt] = a[l];
return;
}
ll mid = (l + r) >> 1;
build(lson);
build(rson);
PushUP(rt);
}
void update(ll left, ll right, ll l, ll r, ll rt)
{
if(left <= l && r <= right)
{
if(tree[rt] <= r - l + 1) return;
else
{
if(l == r)
{
tree[rt] = (ll)sqrt((double)tree[rt]);
return;
}
}
}
ll mid = (l + r) >> 1;
PushUP(rt);
if(left <= mid) update(left, right, lson);
PushUP(rt);
if(right > mid) update(left, right, rson);
PushUP(rt);
}
ll query(ll left, ll right, ll l, ll r, ll rt)
{
ll res = 0;
if(left <= l && right >= r)
{
return tree[rt];
}
ll mid = (l + r) >> 1;
if(left <= mid) res += query(left, right, lson);
if(right > mid) res += query(left, right, rson);
return res;
}
private:
void PushUP(ll rt)
{
tree[rt] = tree[rt<<1] + tree[rt<<1|1];
}
}T;
int main()
{
while(~scanf("%lld",&n))
{
t++;
printf("Case #%d:\n",t);
memset(a, 0, sizeof(a));
for(ll i = 1; i <= n; i++)
a[i] = read();
T.build(1,n,1);
m = read();
for(ll i = 1; i <= m; i++)
{
ll opt, x, y;
opt = read();
x = read();
y = read();
if(y < x) swap(x, y);
if(opt == 0)
T.update(x,y,1,n,1);
else
printf("%lld\n",T.query(x,y,1,n,1));
}
}
return 0;
}
【SP2713 GSS4 - Can you answer these queries IV】 题解的更多相关文章
- 线段树 SP2713 GSS4 - Can you answer these queries IV暨 【洛谷P4145】 上帝造题的七分钟2 / 花神游历各国
SP2713 GSS4 - Can you answer these queries IV 「题意」: n 个数,每个数在\(10^{18}\) 范围内. 现在有「两种」操作 0 x y把区间\([x ...
- SP2713 GSS4 - Can you answer these queries IV(线段树)
传送门 解题思路 大概就是一个数很少次数的开方会开到\(1\),而\(1\)开方还是\(1\),所以维护一个和,维护一个开方标记,维护一个区间是否全部为\(1/0\)的标记.然后每次修改时先看是否有全 ...
- SP2713 GSS4 - Can you answer these queries IV
题目大意 \(n\) 个数,和在\(10^{18}\)范围内. 也就是\(\sum~a_i~\leq~10^{18}\) 现在有两种操作 0 x y 把区间[x,y]内的每个数开方,下取整 1 x y ...
- SP2713 GSS4 - Can you answer these queries IV 分块
问题描述 LG-SP2713 题解 分块,区间开根. 如果一块的最大值是 \(1\) ,那么这个块就不用开根了. 如果最大值不是 \(1\) ,直接暴力开就好了. \(\mathrm{Code}\) ...
- 洛谷P4145 上帝造题的七分钟2 / 花神游历各国(重题:洛谷SP2713 GSS4 - Can you answer these queries IV)
题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是便有了对一段 ...
- GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)
GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...
- GSS4 - Can you answer these queries IV(线段树懒操作)
GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...
- 题解【SP2713】GSS4 - Can you answer these queries IV
题目描述 You are given a sequence \(A\) of \(N(N \leq 100,000)\) positive integers. There sum will be le ...
- 「SP2713」GSS4 - Can you answer these queries IV
传送门 Luogu 解题思路 区间开方以及区间求和. 考虑用线段树来做. 开方操作看似没有任何结合律可言,但这题有另外一个性质: 一个数的初始值不超过 \(10^{18}\) ,而这个数被开方6次左右 ...
随机推荐
- windows emacs 中拷贝文件
cp d:/workspace/LoginWeb/target/LoginWeb.war D:/Program\ Files/apache-tomcat-7.0.78/webapps/LoginWeb ...
- 解决:springmvc maven 项目搭建完后没有src目录,而且maven导入很慢
前言:在搭建springmvc maven项目中遇到的问题做总结,比如搭建后没有src,同时这里也解决了搭建后maven导入很慢的问题. 问题: 1.发现创建出来的maven项目没有src文件 ,而且 ...
- MySQL三层逻辑架构
MySQL的存储引擎架构将查询处理与数据的存储/提取相分离.下面是MySQL的逻辑架构图: 第一层负责连接管理.授权认证.安全等等. 每个客户端的连接都对应着服务器上的一个线程.服务器上维护了一个线程 ...
- 深入分析ReentrantLock公平锁和非公平锁的区别 (转)
在ReentrantLock中包含了公平锁和非公平锁两种锁,通过查看源码可以看到这两种锁都是继承自Sync,而Sync又继承自AbstractQueuedSynchronizer,而AbstractQ ...
- Inter网关做Team的方法
1.到Inter官网上找到相关驱动程序 2.在安装过程中,要求勾选高级网络 3.驱动安装完成后,打开网卡的属性窗口,在“分组”选项卡中,勾中,并输入Team名称 4.选择需要做Team的网卡 5.选择 ...
- Code Signal_练习题_alternatingSums
Several people are standing in a row and need to be divided into two teams. The first person goes in ...
- cfE. Ehab and a component choosing problem(贪心)
题意 题目链接 给出一棵树,每个节点有权值,选出\(k\)个联通块,最大化 \[\frac{\sum_{i \in S} a_i}{k}\] Sol 结论:选出的\(k\)个联通块的大小是一样的且都等 ...
- 关于log4j知识
今天下午接触到log4j知识,花了几个小时,百度了一圈,总算是懂了一些. log4j的作用:log4j是一个日志输出的插件专门用来进行日志管理的,根据我的理解就是用来执行我们用来检测程序bug的Sys ...
- Laravel之Ueditor
1.访问网址http://ueditor.baidu.com/website/download.html下载合适的编辑器版本 2.按照插件包中的index.html样式,布局页面 3.如果需要使用表单 ...
- 新手嘛,先学习下 Vue2.0 新手入门 — 从环境搭建到发布
Vue2.0 新手入门 — 从环境搭建到发布 转自:http://www.runoob.com/w3cnote/vue2-start-coding.html 具体文章详细就不搬了,步骤可过去看,我这就 ...