【BZOJ3211】【并查集+树状数组】花神游历各国
Description
.jpg)
Input
.jpg)
Output
每次x=1时,每行一个整数,表示这次旅行的开心度
Sample Input
1 100 5 5
5
1 1 2
2 1 2
1 1 2
2 2 3
1 1 4
Sample Output
11
11
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <iomanip>
#include <string>
#include <cmath>
#include <queue>
#include <map> const int MAXN = + ;
const int MAX = + ;
using namespace std;
typedef long long ll;
int n;
ll C[MAXN];
int data[MAXN], parent[MAXN]; int SQRT(int x){return (int)floor(sqrt((double)x * 1.0));}
int lowbit(int x){return x & -x;}
void add(int x, int val){
while (x <= n){
C[x] += val;
x += lowbit(x);
}
return;
}
ll sum(int x){
ll cnt = ;
while (x > ){
cnt += C[x];
x -= lowbit(x);
}
return cnt;
}
int find(int x) {return parent[x] == x? x : parent[x] = find(parent[x]);}
void init(){
memset(C, , sizeof(C));
scanf("%d", &n);
for (int i = ; i <= n; i++){
scanf("%d", &data[i]);
add(i, data[i]);
parent[i] = i;
if (data[i] == || data[i] == ) parent[i] = i + ;
}
parent[n + ] = n + ;
}
void work(){
int q;
scanf("%d", &q);
for (int i = ; i <= q; i++){
int t, x, y;
scanf("%d%d%d", &t, &x, &y);
if (t == ) printf("%lld\n", sum(y) - sum(x - ));
else{
for (int i = x; i <= y; i = find(i + )){
int tmp = data[i];
data[i] = SQRT(data[i]);
add(i, data[i] - tmp);
if (data[i] <= ) parent[i] = find(i + );
}
}
}
} int main(){
int T;
#ifdef LOCAL
freopen("data.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
init();
work();
return ;
}
【BZOJ3211】【并查集+树状数组】花神游历各国的更多相关文章
- BZOJ-3211花神游历各国 并查集+树状数组
一开始想写线段树区间开方,简单暴力下,但觉得变成复杂度稍高,懒惰了,编了个复杂度简单的 3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MB Subm ...
- BZOJ3211 花神游历各国 并查集 树状数组
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ3211 题意概括 有n个数形成一个序列. m次操作. 有两种,分别是: 1. 区间开根(取整) 2. ...
- hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点)
hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点) 题意: 给一张无向连通图,有两种操作 1 u v 加一条边(u,v) 2 u v 计算u到v路径上桥的个数 ...
- 【bzoj4869】[Shoi2017]相逢是问候 扩展欧拉定理+并查集+树状数组
题目描述 Informatik verbindet dich und mich. 信息将你我连结. B君希望以维护一个长度为n的数组,这个数组的下标为从1到n的正整数.一共有m个操作,可以分为两种:0 ...
- 【BZOJ3211】花神游历各国 并查集+树状数组
[BZOJ3211]花神游历各国 Description Input Output 每次x=1时,每行一个整数,表示这次旅行的开心度 Sample Input 41 100 5 551 1 22 1 ...
- HDU 5458 Stability(双连通分量+LCA+并查集+树状数组)(2015 ACM/ICPC Asia Regional Shenyang Online)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connecte ...
- la4730(并查集+树状数组)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=30& ...
- HDU 4750 Count The Pairs ★(图+并查集+树状数组)
题意 给定一个无向图(N<=10000, E<=500000),定义f[s,t]表示从s到t经过的每条路径中最长的边的最小值.Q个询问,每个询问一个t,问有多少对(s, t)使得f[s, ...
- 【BZOJ4382】[POI2015]Podział naszyjnika 堆+并查集+树状数组
[BZOJ4382][POI2015]Podział naszyjnika Description 长度为n的一串项链,每颗珠子是k种颜色之一. 第i颗与第i-1,i+1颗珠子相邻,第n颗与第1颗也相 ...
随机推荐
- haproxy实现mysql slave负载均衡
简单画一个图: 一.服务器规划 192.168.116.132 (master) -->写操作 192.168.116.129 (slave1) -->读操作 192.168.116. ...
- 踩过的坑之-----selector
打算踏踏实实的做技术了,以前总是毛毛躁躁的将代码粘贴复制完事能跑起来就行.最近慢慢感觉这样真的对自己的时间和经历是一种浪费. 就从最基本的做起吧,今天做了一个selector,在按钮上面添加效果, & ...
- page-object使用(2)---elements
elements就是html元素下所有的标签.用page-object你可以找到并定位html页面下绝大多数的元素,这个文章列出了可定位的这些元素,生成的方法,和依据什么关键字来找到这些元素. BUT ...
- Two kinds of Quaternion SlerpImp (Unity)
using UnityEngine;using System.Collections; public class SlerpImp{ static float Dot(Quaternion a, Qu ...
- [转]关于strtok和strtok_r函数的深度研究
在linux环境下,字符串分割的函数中,大家比较常用的是strtok函数,这个函数用处很大,但也有一些问题,以下将深度挖掘一下这个函数的用法,原理,实现,其次,该函数是不可再入函数,但是在linux ...
- Nova 无法向虚机注入密钥
欢迎各位关注我的博客:http://weibo.com/u/216633637 废话开头: 之前参考这位同学的博客http://www.cnblogs.com/awy-blog/p/3447176.h ...
- 转 MySQL 用户权限详细汇总
http://blog.csdn.net/mchdba/article/details/45934981 1,MySQL权限体系 MySQL 的权限体系大致分为5个层级: 全局层级: 全局权限适用于一 ...
- SQL Server 中关于EXCEPT和INTERSECT的使用方法
熟练使用SQL Server中的各种使用方法会给查询带来非常多方便.今天就介绍一下EXCEPT和INTERSECT.注意此语法仅在SQL Server 2005及以上版本号支持. EXCEPT是指在第 ...
- Python获取当前时间 分类: python 2014-11-08 19:02 132人阅读 评论(0) 收藏
Python有专门的time模块可以供调用. <span style="font-size:14px;">import time print time.time()&l ...
- zedboard--交叉编译Opencv库的生成 分类: shell ubuntu fool_tree的笔记本 ZedBoard OpenCV 2014-11-08 18:57 171人阅读 评论(0) 收藏
Opencv的移植,xzyfeixiang和rainysky的博客. 第一步肯定是下载opencv的源码包 第二步已经做好的交叉编译环境. 第三步下载安装cmake apt-get install ...