【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次左右 ...
随机推荐
- K:求取数组中最大连续子序列和的四个算法
相关介绍: 求取数组中最大连续子序列和问题,是一个较为"古老"的一个问题.该问题的描述为,给定一个整型数组(当然浮点型也是可以的啦),求取其下标连续的子序列,且其和为该数组的所有 ...
- MySQL并发控制
并发即指在同一时刻,多个操作并行执行.MySQL对并发的处理主要应用了两种机制——是“锁”和“多版本控制”. 锁 锁分为读锁和写锁两种,也称作共享锁和排他锁.因为多个读操作同时进行是不会破坏数据的,所 ...
- javascript中闭包最简单的简绍
javascript中闭包是什么 JavaScript 变量可以是局部变量或全局变量.私有变量可以用到闭包.闭包就是将函数内部和函数外部连接起来的一座桥梁. 函数的闭包使用场景:比如我们想要一个函数来 ...
- UOJ#55 [WC2014]紫荆花之恋
题目描述 强强和萌萌是一对好朋友.有一天他们在外面闲逛,突然看到前方有一棵紫荆树.这已经是紫荆花飞舞的季节了,无数的花瓣以肉眼可见的速度从紫荆树上长了出来. 仔细看看的话,这个大树实际上是一个带权树. ...
- BZOJ1031 [JSOI2007]字符加密
Description 喜欢钻研问题的JS同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密办法 :把需要加密的信息排成一圈,显然,它们有很多种不同的读法.例如下图,可以读作 ...
- Date()函数的用法
- #include <unistd.h> 的作用
原文:http://blog.csdn.net/ybsun2010/article/details/24832113 由字面意思,unistd.h是unix std的意思,是POSIX标准定义的uni ...
- restframework类继承图
- leetcode BFS
1. word ladder class Solution { public: int ladderLength(string beginWord, string endWord, unordered ...
- configparser logging collections 模块
configparser 模块: 这是一个写入的模块就是把你的信息给写入的模块 #这是一个把信息写入example文件内import configparserconfig = configparser ...