【题目分析】

区间开方+区间求和。

由于区间开方次数较少,直接并查集维护下一个不是1的数的位置,然后暴力修改,树状数组求和即可。

这不是BZOJ上上帝造题7分钟嘛

【代码】

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
long long a[100001],f[100001],n,q,op,l,r;
long long t[100001];
inline long long gf(long long k)
{
if (f[k]==k) return k;
else return f[k]=gf(f[k]);
}
inline void add(long long x,long long f)
{
for (;x<=n;x+=x&(-x))
t[x]+=(ll)f;
}
inline long long gs(long long x)
{
long long ret=0;
for (;x;x-=x&(-x)) ret+=t[x];
return ret;
}
int main()
{
int kas=0;
while (scanf("%lld",&n)!=EOF)
{
printf("Case #%d:\n",++kas);
memset(t,0,sizeof t);
for (long long i=1;i<=n;++i) scanf("%lld",&a[i]),f[i]=i;
f[n+1]=n+1;
for (long long i=1;i<=n;++i) add(i,a[i]);
scanf("%lld",&q);
for (long long zz=1;zz<=q;++zz)
{
scanf("%lld",&op);
if (op==0)
{
scanf("%lld%lld",&l,&r);
if (l>r) swap(l,r);
long long i=l;
while (i<=r)
{
i=gf(f[i]);
if (i>r) break;
long long tmp=a[i];
a[i]=(long long)sqrt(a[i]);
add(i,a[i]-tmp);
if (a[i]==1) f[i]=f[i]+1;
gf(f[i]);
i++;
}
}
else
{
scanf("%lld%lld",&l,&r);
if (l>r) swap(l,r);
printf("%lld\n",gs(r)-gs(l-1));
}
}
printf("\n");
}
}

  

SPOJ GSS4 Can you answer these queries IV ——树状数组 并查集的更多相关文章

  1. SPOJ GSS4 Can you answer these queries IV

    Time Limit: 500MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are g ...

  2. GSS4 - Can you answer these queries IV(线段树懒操作)

    GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...

  3. 线段树 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 ...

  4. GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)

    GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...

  5. SP2713 GSS4 - Can you answer these queries IV(线段树)

    传送门 解题思路 大概就是一个数很少次数的开方会开到\(1\),而\(1\)开方还是\(1\),所以维护一个和,维护一个开方标记,维护一个区间是否全部为\(1/0\)的标记.然后每次修改时先看是否有全 ...

  6. GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树

    GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...

  7. CodeForces - 369E Valera and Queries(树状数组)

    CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...

  8. 题解【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 ...

  9. Spoj 2713 Can you answer these queries IV 水线段树

    题目链接:点击打开链接 题意: 给定n长的序列 以下2个操作 0 x y 给[x,y]区间每一个数都 sqrt 1 x y 问[x, y] 区间和 #include <stdio.h> # ...

随机推荐

  1. HDU 4291 A Short problem 短问题 (递推,找规律)

    题意: 给出递推式 g(n) = 3g(n - 1) + g(n - 2),且g(1) = 1,g(0) = 0.求g( g( g(n))) mod 109 + 7. 思路: 要求的g( g( g(n ...

  2. [转]八款开源Android游戏引擎

    八款开源Android游戏引擎 1.Angle Angle是一款专为Android平台设计的,敏捷且适合快速开发的2D游戏引擎,基于OpenGL ES技术开发.该引擎全部用Java代码编写,并且可以根 ...

  3. VGG16学习笔记

    转载自:http://deanhan.com/2018/07/26/vgg16/ 摘要 本文对图片分类任务中经典的深度学习模型VGG16进行了简要介绍,分析了其结构,并讨论了其优缺点.调用Keras中 ...

  4. video 的使用

    video ui给了默认的暂停图片 利用video自身的属性很难达到效果  这里自己写了个 简单记录下 <div class="cg-container video-img" ...

  5. win10搭建Java环境

    一.下载地址    jdk和jre官方网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 根据你的系统选择你需要 ...

  6. java B转换KB MB GB TB PB EB ZB

    public static String readableFileSize(long size) { if (size <= 0) { return "0"; } final ...

  7. visual c++ build tools的安装与使用

    https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=BuildTools&r ...

  8. shell脚本,判断给出的字符串是否相等。

    第一种方法[root@localhost wyb]# .sh #!/bin/bash #判断给出的字符串是否相等 read -p "Please Input a number:" ...

  9. http常用状态吗以及分别代表什么意思?

    http常用状态码: 状态码 定义 说明 1xx 信息 街道请求继续处理 2xx 成功 成功的收到.理解.接受 3xx 重定向 浏览器需要执行某些特殊处理一完成请求 4xx 客户端错误 请求的语法有问 ...

  10. axure笔记--变量值在页面之间的传递

    fx     先给局部变量赋值,再添加到上面,即给全局变量赋值. 实现页面跳转: 1.打开链接,选择要跳转的下个页面---确定 2.打开那个下一个跳转的页面,要得到上个页面的值,需要到页面交互---页 ...