HDU 4351 Digital root 线段树区间合并
依然不是十分理解……待考虑……
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> #define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1 using namespace std; const int MAXN = ; struct node
{
int num;
int lnode, rnode;
int root;
node(): num(), lnode(), rnode(), root(){ }
}; int root[ MAXN << ];
int num[ MAXN << ];
int lnode[ MAXN << ];
int rnode[ MAXN << ];
int all[ << ][ << ]; int GetRoot( int a )
{
if ( !a ) return ;
if ( a % ) return a % ;
return ;
} void init()
{
for ( int i = ; i < ( << ); ++i )
for ( int j = ; j < ( << ); ++j )
{
all[i][j] = ;
for ( int x = ; x < ; ++x )
if ( i & ( << x ) )
{
for ( int y = ; y < ; ++y )
if ( j & ( << y ) )
all[i][j] |= ( << GetRoot( x + y ) );
}
}
return;
} void PushUp( int rt )
{
int lc = rt << ;
int rc = rt << | ;
root[rt] = root[lc] | root[rc] | all[ rnode[lc] ][ lnode[rc] ];
num[rt] = all[ num[lc] ][ num[rc] ];
lnode[rt] = lnode[lc] | all[ num[lc] ][ lnode[rc] ];
rnode[rt] = rnode[rc] | all[ num[rc] ][ rnode[lc] ];
return;
} void build( int l, int r, int rt )
{
if ( l == r )
{
int a;
scanf( "%d", &a );
a = GetRoot(a);
lnode[rt] = rnode[rt] = num[rt] = root[rt] = ( << a );
return;
} int m = ( l + r ) >> ;
build( lson );
build( rson );
PushUp( rt );
return;
} node Query( int L, int R, int l, int r, int rt )
{
if ( L <= l && r <= R )
{
node D;
D.root = root[rt];
D.lnode = lnode[rt];
D.rnode = rnode[rt];
D.num = num[rt];
return D;
} int m = ( l + r ) >> ; if ( R <= m ) return Query( L, R, lson );
else if ( L > m ) return Query( L, R, rson );
else
{
node LD, RD, D;
LD = Query( L, R, lson );
RD = Query( L, R, rson );
D.root = LD.root | RD.root | all[ LD.rnode ][ RD.lnode ];
D.num = all[ LD.num ][ RD.num ];
D.lnode = LD.lnode | all[ LD.num ][ RD.lnode ];
D.rnode = RD.rnode | all[ RD.num ][ LD.rnode ];
return D;
}
} int main()
{
init();
int T, cas = ;
scanf( "%d", &T );
while ( T-- )
{
int n;
scanf( "%d", &n );
build( , n, ); int Q;
scanf( "%d", &Q );
printf( "Case #%d:\n", ++cas );
while ( Q-- )
{
int a, b;
scanf( "%d%d", &a, &b );
node ans = Query( a, b, , n, ); int cnt = ;
bool first = false;
for ( int i = ; i >= && cnt < ; --i )
if ( ans.root & ( << i ) )
{
if ( first ) putchar(' ');
printf( "%d", i );
first = true;
++cnt;
}
for ( ; cnt < ; ++cnt ) printf(" -1");
puts("");
} if ( T ) puts("");
}
return ;
}
HDU 4351 Digital root 线段树区间合并的更多相关文章
- HDU 6638 - Snowy Smile 线段树区间合并+暴力枚举
HDU 6638 - Snowy Smile 题意 给你\(n\)个点的坐标\((x,\ y)\)和对应的权值\(w\),让你找到一个矩形,使这个矩阵里面点的权值总和最大. 思路 先离散化纵坐标\(y ...
- hdu 3397 Sequence operation (线段树 区间合并 多重标记)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3397 题意: 给你一串01串,有5种操作 0. 区间全部变为0 1.区间全部变为1 2.区间异或 3.询问 ...
- HDU 5316——Magician——————【线段树区间合并区间最值】
Magician Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- hdu 4453 约会安排(线段树区间合并)
约会安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- HDU 1540 Tunnel Warfare 线段树区间合并
Tunnel Warfare 题意:D代表破坏村庄,R代表修复最后被破坏的那个村庄,Q代表询问包括x在内的最大连续区间是多少 思路:一个节点的最大连续区间由(左儿子的最大的连续区间,右儿子的最大连续区 ...
- (简单) HDU 3308 LCIS,线段树+区间合并。
Problem Description Given n integers. You have two operations: U A B: replace the Ath number by B. ( ...
- hdu 3308 LCIS(线段树区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3308 LCIS Time Limit: 6000/2000 MS (Java/Others) ...
- hdu 1540 Tunnel Warfare 线段树 区间合并
题意: 三个操作符 D x:摧毁第x个隧道 R x:修复上一个被摧毁的隧道,将摧毁的隧道入栈,修复就出栈 Q x:查询x所在的最长未摧毁隧道的区间长度. 1.如果当前区间全是未摧毁隧道,返回长度 2. ...
- HDU 3911 线段树区间合并、异或取反操作
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...
随机推荐
- 万网域名解析到IP地址
进入https://home.console.aliyun.com/#/的阿里云控制台 再自己购买的域名列表里进行操作 添加一个A解析
- Nginx模块开发-理解HTTP配置
理解HTTP配置 相关数据结构 先明白Nginx下述数据结构,再理解 HTTP配置的解析与合并过程 ngx_module_t 官方API typedef struct{ NGX_MODULE_V1; ...
- 快书包CEO徐智明反思:我犯下哪些错误
新浪科技 刘璨 1月23日,快书包CEO徐智明在微博上公开“叫卖”快书包,在业内引起不小反响.这家创立于2010年要做“网上711”的创业公司,曾以独特的“一小时送达”服务在业内成为关注焦点. “如果 ...
- thinkphp中curl的使用,常用于接口
/lib/action/PublicAction.class.php class PublicAction extends Action{ //curl,返回数组 public function ge ...
- SQL Server 数据库最小宕机迁移方案
一.目的 在做SQL Server数据库维护的时候,当上司要求我们把几十G的数据文件搬动到其它服务器,并且要求最小宕机时间的时候,我们有没什么方案可以做到这些要求呢? 在这里我们假设这两台机器并不是在 ...
- C语言基础:数组和字符串
数组:数组的定义注意点 数组初始化正确写法: int args[5] = {1,23,32,4,5}; int args[5] = {12,23}; int args[5] = {[3]=23, [4 ...
- Codeforces Round #343 (Div. 2) C. Famil Door and Brackets
题目链接: http://codeforces.com/contest/629/problem/C 题意: 长度为n的括号,已经知道的部分的长度为m,现在其前面和后面补充‘(',或')',使得其长度为 ...
- vs2010中臃肿的ipch和sdf文件
使用VS2010建立C++解决方案时,会生成SolutionName.sdf和一个叫做ipch的文件夹,这两个文件再加上*.pch等文件使得工程变得非常的庞大,一个简单的程序都会占用几十M的硬盘容量, ...
- spoj 78
数学 组合 隔板法 #include <iostream> #include <cstring> #include <cstdio> #include <s ...
- unity3d旋转摄像机脚本
void Update () { )) { if (axes == RotationAxes.MouseXAndY) { // Read the mouse input axis rotationX ...