ZOJ 3886

题意:

定义一种NicoNico数x,x有下面特征:
全部不大于x且与x互质的数成等差数列,如x = 5 ,与5互素且不大于5的数1,2,3,4成等差数列。则5是一个NicoNico数。

再定义三种操作:
1.南小鸟询问[L, R]内有多少个NicoNico数;
2.果皇把[L, R]内的数全部对v取余;
3.果皇将第K个数换成X。

然后给你一个数列,并对这个数列运行若干操作

思路:

这样的问题果断要用LoveLive树线段树来做!
首先我们通过打表发现NicoNico数仅仅可能是素数。2的n次幂。6,所以能够先预处理,对范围内的全部NicoNico数进行标记。
建树过程:假设是NicoNico数则节点值为1,不是则为0。

更新操作1:对区间内的数进行取模即是区间改动。这里能够优化一下,假设区间最大值小于v,则不须要改动。

更新操作2:即单点改动。

查询操作:输出询问区间和就可以。

时间复杂度:
预处理:O(x)
建树:O(n)
查询与更新:操作次数O(m),每次操作O(logn)加起来是O(mlogn)

羞耻的代码君:

这次代码风格。

重在理解重在理解。

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>using namespace std;#define clr( x , y ) memset(x,y,sizeof(x))
#define cls( x ) memset(x,0,sizeof(x))
#define mp make_pair
#define pb push_back
#define lson l , mid , root << 1
#define rson mid + 1 , r , root << 1 | 1
typedef long long lint;
typedef long long ll;
typedef long long LL;const int maxNico = 1e7 + 500 ;
const int maxHonoka = 1e5 + 7 ;
int Honoka_max[10 * maxHonoka] ;
int Honoka_sum[10 * maxHonoka] ;
bool Nico_prime[maxNico];
map<int , int> NicoNicoNi;/* にっこにっこにー☆あなたのハートににこにこにー 笑颜届ける矢澤にこにこー にこにーって覚えてラブにこー */void init(){NicoNicoNi[0] = NicoNicoNi[6] = 1;for( int i = 0 ; i <= 31 ; i++ ){NicoNicoNi[( 1 << i )] = 1;}cls( Nico_prime );for( int  i = 2 ; i * i <= maxNico ; i++ ){if( !Nico_prime[i] )for( int j = i * i ; j <= maxNico ; j+=i )Nico_prime[j] = 1;}for( int i = 2 ; i <= maxNico ; i++ ) if( !Nico_prime[i] ) NicoNicoNi[i] = 1;
}void push_Yazawa( int root ){Honoka_max[root] = max( Honoka_max[ root << 1 ] , Honoka_max[ root << 1 | 1 ] );Honoka_sum[root] = Honoka_sum[ root << 1 ] + Honoka_sum[ root << 1 | 1 ] ;
}void build_Kotori( int l , int r , int root ){if( l == r ){scanf( "%d" , &Honoka_max[root] );if( NicoNicoNi[Honoka_max[root]] )Honoka_sum[root] = 1;elseHonoka_sum[root] = 0;return ;}int mid = ( l + r ) / 2 ;build_Kotori( lson );build_Kotori( rson );push_Yazawa( root );
}void Honoka1( int ql , int qr , int x , int l , int r , int root ){if( qr < l || ql > r )return ;if( Honoka_max[root] < x) return ;if( l == r ){Honoka_max[root] %= x ;if( NicoNicoNi[Honoka_max[root]] )Honoka_sum[root] = 1;elseHonoka_sum[root] = 0;return ;}int mid = ( l + r ) / 2 ;Honoka1( ql , qr , x , lson );Honoka1( ql , qr , x , rson );push_Yazawa( root );
}void Honoka2( int pos , int x , int l , int r , int root ){if( l == pos && r == pos ){Honoka_max[root] = x ;if( NicoNicoNi[x] )Honoka_sum[root] = 1;elseHonoka_sum[root] = 0;return ;}int mid = ( l + r ) / 2 ;if( mid >= pos )Honoka2( pos , x , lson );elseHonoka2( pos , x , rson );push_Yazawa( root );
}int Kotori( int ql , int qr , int l , int r , int root ){if( ql > r || qr < l )return 0 ; if( ql <= l && qr >= r )return Honoka_sum[root];int res = 0 ;int mid = ( l + r ) / 2 ;if( ql <= mid )res += Kotori( ql , qr , lson ) ;if( qr > mid )res += Kotori( ql , qr , rson ) ;return res;
}
int main(){//freopen("input.txt","r",stdin);init();int n ; while( cin >> n ){build_Kotori( 1 , n , 1 ) ;int m ;cin >> m ;for( int i = 1 ; i <= m ; i++ ){int num ;scanf( "%d" , &num );if( num == 1 ){int left , right ;scanf( "%d%d" , &left , &right ) ;printf( "%d\n" , Kotori( left , right , 1 , n , 1 ));}else if( num == 2 ){int left , right , mod ;scanf( "%d%d%d" , &left , &right , &mod ) ;Honoka1( left , right , mod , 1 , n , 1 ) ;}else if( num == 3 ){int pos , x ;scanf( "%d%d" , &pos , &x ) ;Honoka2( pos , x , 1 , n , 1 ) ;}}}return 0;
}

ZOJ 3886 Nico Number(筛素数+Love(线)Live(段)树)相关推荐

  1. ZOJ 3886 Nico Number (线段树)

    题目地址:ZJU 3886 这个题需要想到一点,因为对一个数x不断取模的话,而且设定他小于模才会进行取余操作的话,那么最多只会进行logx次,因为每次取模都会使x最少折半.然后想到了这点就很好做了.对 ...

  2. 2404 Super Prime(欧拉筛素数)

    2404 Super Prime(欧拉筛素数) Problem Description We all know, prime is a kind of special number which has ...

  3. [SDOI2008]沙拉公主的困惑 线性筛 素数+欧拉

    本文为博主原创文章,欢迎转载,请注明出处 www.cnblogs.com/yangyaojia [SDOI2008]沙拉公主的困惑 线性筛 素数+欧拉 题目大意 给定n,m,求在1到n!内与m!互质的 ...

  4. 线性筛素数(欧拉筛)

    欧拉筛是O(n)复杂度的筛素数算法,1秒内埃筛能处理1e6的数据,而1e7的数据就必须用欧拉筛了. 埃筛的基本思想是:素数的倍数一定是合数. 欧拉筛基本思想是:任何数与素数的乘积一定是合数 算法概述: ...

  5. 普及组模板——线性筛素数

    题目:[模板]线性筛素数(洛谷_3383) #include<iostream> #include<cstdio> #include<algorithm> #inc ...

  6. P3383 【模板】线性筛素数

    https://www.luogu.com.cn/problem/P3383 //线性筛法 /* P3383 [模板]线性筛素数 https://www.luogu.com.cn/problem/P3 ...

  7. poj 2262 Goldbach's Conjecture(筛素数)

    2018-5-23 验证哥德巴赫猜想,直接将素数全部筛出来,然后从小到大枚举即可,找到的第一个满足条件的肯定就是差值最大的即满足题意的. 普通筛素数: #include<iostream> ...

  8. 改进的筛素数法 2014-11-29 16:16 29人阅读 评论(0) 收藏...

    最简单的筛素数法方法就是从2开始,将所以2的倍数去掉,然后从3开始,将3的倍数去掉.根据这样很容易写出代码,下面代码就是是筛素数法得到100以内的素数并保存到primes[]数组中. [cpp] vi ...

  9. Composite Coloring(思维 数论(筛素数 分解质因数))

    (29条消息) CodeForces - 1332B Composite Coloring(数论+构造)_Frozen_Guardian的博客-CSDN博客 (29条消息) codeforces 13 ...

最新文章

  1. 基于机器学习的文本分类!
  2. Meson,用于协调和调度Netflix推荐工作流的架构
  3. 【开源】高颜值 功能强大的开源Markdown编辑器
  4. 微信,QQ这类IM app怎么做——谈谈Websocket
  5. linux——线程(2)
  6. 推荐一个比FiddlerCore好用的HTTP(S)代理服务器
  7. mysql中毫秒的保存类型
  8. [NOI 2010]超级钢琴
  9. 水系图一般在哪里找得到_水系电池再发Nature,事实力证或将迎来发展的春天!...
  10. 微师电脑客户端 附使用教程
  11. 【谷歌浏览器】国内如何配置谷歌浏览器使用
  12. win 如何生成ssh密钥
  13. [RK3399][Android7.1.1]系统强制App横屏显示
  14. Ubuntu 20.04.2.0 LTS 下Geany 1.36的“编译文件”和“生成当前文件”两个按键不可用
  15. Android 实现浏览器打开app
  16. 微信小程序开发《6 .框架之逻辑层》
  17. Thinkphp5的项目配置到西部数码虚拟主机
  18. 上传图片就能建模?!一个人人可用的在线三维大场景重建云平台
  19. 本源量子与德美牵头成立产业联盟,生物化学正式进入量子计算“赛道”|现场专访
  20. python画图模糊_Python绘图scikitfuzzy没有响应

热门文章

  1. 数据结构之线性表及C语言实现
  2. iOS 开发:彻底理解 iOS 内存管理(MRC 篇)
  3. hibernate left join fetch 出错的问题
  4. FFmpeg源码分析:视频滤镜介绍(上)
  5. DNA计算机及DNA存储
  6. 秋招小结:感受+面经(CV算法岗)
  7. Qt设置按钮背景图片,点击不显示背景
  8. 单调函数有界性类题目解法
  9. WiFi万能钥匙破解显密码版。
  10. 正念的奇迹 - 喧嚣的世界中获取安宁