【题目分析】

区间开方+区间求和。

由于区间开方次数较少,直接并查集维护下一个不是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. linux下phpstudy的搭建以及网站的搭建

    step1: 下载SSH连接到IP地址(阿里云上购买的) step2: 安装下载phpstudywget -c http://lamp.phpstudy.net/phpstudy.bin chmod ...

  2. UVM之uvm_phase

    UVM中的phase机制很有意思,它能让UVM启动之后,自动执行所有的流程.UVM 的user guide 中对uvm_phase的定义如下: This base class defines ever ...

  3. jdbc接口的一种类比——打酱油

    jdbc很简单,这里只是为了方便自己的记忆.模型也许有缺陷,但本质是相同的. jdbc可以屏蔽数据库的底层的不同,让我们有能力用java语言统一访问不同的数据库.就像打酱油一样,可以去超市买,也可以去 ...

  4. navicate与mysql连接的中文乱码问题

    1. 在navicate中查看 show variables like'char%'; show variables like 'collation_%'; 2.在mysql中查看 通过对比可以发现两 ...

  5. UVA 1661 Equation (后缀表达式,表达式树,模拟,实现)

    题意:给出一个后缀表达式f(x),最多出现一次x,解方程f(x) = 0. 读取的时候用一个栈保存之前的结点,可以得到一颗二叉树,标记出现'X'的路径,先把没有出现'X'的子树算完,由于读取建树的时候 ...

  6. Android(java)学习笔记148:网易新闻RSS客户端应用编写逻辑过程

    1.我们的项目需求是编写一个新闻RSS浏览器,RSS(Really Simple Syndication)是一种描述和同步网站内容的格式,是使用最广泛的XML应用.RSS目前广泛用于网上新闻频道,bl ...

  7. Scalatra

    SBT和giter8 在你开始着手之前,你需要安装两个工具(我假设你已经安装了JDK1.6+).我将给你提供简缩的安装指令,详细版的安装指令可通过 下面的scalatra页面找到( http://ww ...

  8. SpringAOP 设计原理

    1.  设计原理 引入了,代理模式. java 程序执行流: 如果从虚拟机的角度看,整个程序的过程就是方法的调用,我们按照方法的执行顺序,将方法调用成一串. 在方法之间有着Join Point 连接点 ...

  9. vue cli的安装与使用

    一.简介 vue作为前端开发的热门工具,受到前端开发人员的喜爱.为了简化项目的构建,采用vue cli来简化开发. vue cli是一个全局安装的npm包,提供了终端使用的命令.vue create可 ...

  10. java解析sql文件

    package com.athena.ckx.util; import java.io.FileInputStream; import java.io.InputStream; import java ...