这题主要考察观察能力。

2^63最多只需要开7次根号就会变成1,当数字变成1之后就不需要再对其进行操作。

对于含有大于1数字的区间,向下更新。

对于数字全为1的区间,直接返回。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath> #define LL long long int
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define lc rt << 1
#define rc rt << 1 | 1 using namespace std; const int MAXN = ; LL sum[MAXN << ];
bool one[MAXN << ]; void PushUp( int rt )
{
sum[rt] = sum[lc] + sum[rc];
one[rt] = one[lc] && one[rc];
return;
} void build( int l, int r, int rt )
{
if ( l == r )
{
scanf( "%I64d", &sum[rt] );
if ( sum[rt] <= ) one[rt] = true;
else one[rt] = false;
return;
}
int m = ( l + r ) >> ;
build(lson);
build(rson);
PushUp( rt );
return;
} void Update( int L, int R, int l, int r, int rt )
{
if ( one[rt] ) return;
if ( l == r )
{
sum[rt] = (LL)sqrt( (double)sum[rt] );
//之前这里忘了更新one,一直TLE
     if ( sum[rt] <= ) one[rt] = true;
else one[rt] = false;
return;
}
int m = ( l + r ) >> ;
if ( L <= m ) Update( L, R, lson );
if ( R > m ) Update( L, R, rson );
PushUp( rt );
return;
} LL Query( int L, int R, int l, int r, int rt )
{
   //这句不要,之前想错了
   //if ( one[rt] ) return (LL)r - l + 1;
if ( L <= l && r <= R ) return sum[rt]; int m = ( l + r ) >> ;
LL res = ;
if ( L <= m ) res += Query( L, R, lson );
if ( R > m ) res += Query( L, R, rson );
return res;
} int N; int main()
{
int cas = ;
while ( scanf( "%d", &N ) == )
{
build( , N, );
int Q;
scanf( "%d", &Q );
printf( "Case #%d:\n", ++cas );
while ( Q-- )
{
int op, a, b;
scanf( "%d%d%d", &op, &a, &b );
if ( b < a ) swap(a, b);
if ( op )
{
printf("%I64d\n", Query( a, b, , N, ) );
}
else
{
Update( a, b, , N, );
}
}
puts("");
}
return ;
}

最新文章

  1. 《Javascript高级程序设计》:创建对象
  2. css before&amp;after 特殊用途
  3. 阻塞队列LinkedBlockingQueue和并发队列ConcurrentLinkedQueue
  4. Windows 托盘区域显示图标
  5. java的getClass()函数
  6. python安装psycopg2
  7. IOS Remote Notification
  8. event和window.event
  9. SmartCoder每日站立会议04
  10. Akka(37): Http:客户端操作模式
  11. NLog日志管理工具(转)
  12. 找不到BufferedImage这个Class的解决方法
  13. Could not find property &#39;outputFile
  14. Android 资源文件命名与使用
  15. vue省市区三级联动
  16. python数据结构与算法第十五天【二叉树】
  17. Vijos P1459 车展 (treap 任意区间中位数)
  18. istringstream、ostringstream、stringstream 类介绍 和 stringstream类 clear函数的真正用途
  19. 远程桌面连接MySQL遇到的问题及解决方法总结
  20. python3获取主机名、主机IP

热门文章

  1. javascript中的作用域与作用域链
  2. 最近的阅读list
  3. Spring的jdbcTemplate 与原始jdbc 整合c3p0的DBUtils 及Hibernate 对比 Spring配置文件生成约束的菜单方法
  4. 转 MYSQL 命令行大全 (简洁、明了、全面)
  5. Redis 4.0 从节点写入不同步问题
  6. JS - CommonJS、AMD、CMD
  7. select值改变
  8. Form表单提交,js验证
  9. Gson转Map时,Int会变成double解决方法
  10. strak组件(3):URL别名的优化