【题目分析】

区间开方+区间求和。

由于区间开方次数较少,直接并查集维护下一个不是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. Azure Powershell blob中指定的vhd创建虚拟机

    #此脚本用于 Azure 存储账户中已有 vhd 镜像文件创建虚拟机,一般用于做好镜像测试 #----------------------------------------------------- ...

  2. LR中排序脚本

    /* * LoadRunner Java script. (Build: 670) * * Script Description: * */ import lrapi.lr; public class ...

  3. UVA1001 Say Cheese (dijkstra)

    如果没有洞,那么任意两点的最短距离就是直线距离,洞里是瞬间的,所以看成一个点就行了(其实点也可以当作半径为0的洞来处理),洞到洞的最短距离都是圆心距离减去半径.剩下的就是求单源最短路径,是完全图,用不 ...

  4. sort函数的使用

    此篇当作自己的笔记(水平太菜,这都一直没搞明白) sort()函数的用法1)sort函数包含在头文件<algroithm>中,还要结合using namespace std2)sort有三 ...

  5. 用navcat编写定时任务调用存储过程

    最近项目需要改动比较大,数据库结构也有所改变,这时就需要转移旧数据到新库中 第一时间想到的是用代码操作,由于两个库表结构不同,实体什么的得需要重新生成 并编写转移代码,这将是很大的工作量: 然后就想着 ...

  6. C语言中函数参数传递

    C语言中函数参数传递的三种方式 (1)值传递,就是把你的变量的值传递给函数的形式参数,实际就是用变量的值来新生成一个形式参数,因而在函数里对形参的改变不会影响到函数外的变量的值.(2)地址传递,就是把 ...

  7. Bootstrap历练实例:分页的大小

    分页的大小 下面的实例演示了上表中所讨论的 class .pagination-* 的用法: <!DOCTYPE html><html><head><meta ...

  8. ext笔记

    命名   The top-level namespaces and the actual class names should be CamelCased. Everything else shoul ...

  9. JavaScript调试技巧之console.log()详解--2015-08-07

    对于JavaScript程序的调试,相比于alert(),使用console.log()是一种更好的方式,原因在于:alert()函数会阻断 JavaScript程序的执行,从而造成副作用:而cons ...

  10. Django项目部署:使用uwsgi和nginx的方式

    一.背景 前两天制作的个人博客网站基本完工,大致功能具备.但是在部署环节却也处处碰壁,这里也来总结以下,以备将来不时查看以及完善. 二.前提 2.1 需要的知识 django Django是一个基于p ...