Time Limit: 5 Seconds Memory Limit: 196608 KB
You are given a simple task. Given a sequence A[i] with N numbers. You have to perform Q operations on the given sequence. 
Here are the operations: 
* A v l, add the value v to element with index l.(1<=V<=1000) 
* R a l r, replace all the elements of sequence with index i(l<=i<= r) with a(1<=a<=10^6) 
* Q l r, print the number of elements with index i(l<=i<=r) and A[i] is a prime number 
Note that no number in sequence ever will exceed 10^7.

Input 
The first line is a signer integer T which is the number of test cases. 
For each test case, The first line contains two numbers N and Q (1 <= N, Q <= 100000) - the number of elements in sequence and the number of queries. 
The second line contains N numbers - the elements of the sequence. 
In next Q lines, each line contains an operation to be performed on the sequence.

Output 
For each test case and each query,print the answer in one line.

Sample Input 

5 10 
1 2 3 4 5 
A 3 1 
Q 1 3 
R 5 2 4 
A 1 1 
Q 1 1 
Q 1 2 
Q 1 4 
A 3 5 
Q 5 5 
Q 1 5

Sample Output 





4

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define EPS 0.00000001
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull; const int maxn = 1e5+;
const int N = 1e7+;
int t[maxn << ],in[maxn << ],lazy[maxn << ];
int prime[N]; void getprime()
{
for(int i=;i<sqrt(1.0*N);i++)
if(!prime[i])
for(int j=i+i;j<N;j+=i)
prime[j] = ;
prime[] = ;
prime[] = ;
} void pushdown(int i,int b,int e)
{
if(lazy[i])
{
int mid = (b + e) / ;
in[i << ] = !prime[lazy[i]] * (mid - b + );
in[i << | ] = !prime[lazy[i]] * (e - mid); t[i << ] = lazy[i];
t[i << | ] = lazy[i]; lazy[i << ] = lazy[i];
lazy[i << | ] = lazy[i]; lazy[i] = ;
}
} void add(int i,int b,int e,int pos,int val)
{
if(b == e)
{
in[i] -= !prime[t[i]];
t[i] += val;
in[i] += !prime[t[i]];
return ;
}
pushdown(i, b, e); int mid = (b + e) / ;
if(pos <= mid) add(i << , b, mid, pos, val);
else add(i << | , mid + , e, pos, val); in[i] = in[i << ] + in[i << | ];
} void replace(int i,int b,int e,int l,int r,int val)
{
if(b >= l && e <= r)
{
in[i] = (!prime[val]) * (e - b + );
t[i] = val;
lazy[i] = val;
return ;
}
pushdown(i, b, e); int mid = (b + e) / ;
if(r <= mid) replace(i << , b, mid, l, r, val);
else if(l > mid) replace(i<< | , mid + , e, l, r, val);
else
{
replace(i << , b, mid, l, r, val);
replace(i << | , mid + , e, l, r, val);
} in[i] = in[i << ] + in[i << | ];
} int query(int i,int b,int e,int l,int r)
{
if(b >= l && e <= r)
return in[i];
pushdown(i, b, e); int mid = (b + e) / ;
if(r <= mid) return query(i << , b, mid, l, r);
else if(l > mid) return query(i << | , mid + , e, l, r);
else return query(i << , b, mid, l, r) + query(i << | , mid + , e, l, r);
} int main()
{
getprime(); int T;
scanf("%d",&T);
while(T--)
{
char s[];
int n,m,x,a,b,c; scanf("%d%d",&n,&m); memset(t,,sizeof(t));
memset(in,,sizeof(in));
memset(lazy,,sizeof(lazy)); for(int i=;i<=n;i++)
{
scanf("%d",&x);
add(,,n,i,x);
} for(int i=;i<m;i++)
{
scanf("%s%d%d",s,&a,&b);
if(s[] == 'A') add(,,n,b,a); else if(s[] == 'Q') printf("%d\n", query(,,n,a,b)); else
{
scanf("%d",&c);
replace(,,n,b,c,a);
} }
}
}
 

ZOJ 3911Prime Query [素数处理 + 线段树]的更多相关文章

  1. ZOJ 2671 Cryptography 矩阵乘法+线段树

    B - Cryptography Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Subm ...

  2. zoj3886--Nico Number(素数筛+线段树)

    Nico Number Time Limit: 2 Seconds      Memory Limit: 262144 KB Kousaka Honoka and Minami Kotori are ...

  3. ZOJ 1610 Count the Color(线段树区间更新)

    描述Painting some colored segments on a line, some previously painted segments may be covered by some ...

  4. zoj 3888 Twelves Monkeys 二分+线段树维护次小值

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=3888 Twelves Monkeys Time Limit: 5 ...

  5. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

  6. ZOJ 1610 Count the Colors (线段树成段更新)

    题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...

  7. 【HDU5869】 Different GCD Subarray Query 题解 (线段树维护区间GCD)

    题目大意:求区间$[L,R]$中所有子区间产生的最大公因数的个数. ------------------------- 对于$gcd$,我们知道$gcd(a,b,c)=gcd(gcd(a,b),c)$ ...

  8. HDU_3071 Gcd & Lcm game 【素数分解 + 线段树 + 状压】

    一.题目  Gcd & Lcm game 二.分析 非常好的一题. 首先考虑比较暴力的做法,肯定要按区间进行处理,对于$lcm$和$gcd$可以用标准的公式进行求,但是求$lcm$的时候是肯定 ...

  9. ZOJ 3299-Fall the Brick(线段树+离散化)

    题意: n个区间 ,给出区间的左右坐标 ,区间内填满宽度为1的箱子,有m个板子给出板子的高度和左右坐标(同高度不重叠) 所有箱子从上向下落,求每块板子能接到的箱子数. 分析: 首先给的区间很大,一开始 ...

随机推荐

  1. 推荐一款能支持国密SM2浏览器——密信浏览器

    密信浏览器( MeSince Browser )是基于Chromium开源项目开发的国密安全浏览器,支持国密算法和国密SSL证书,同时也支持国际算法及全球信任SSL证书:密信浏览器使用界面清新,干净. ...

  2. 流量监控---iftop

    一.iftop是什么? iftop是类似于top的实时流量监控工具. 官方网站:http://www.ex-parrot.com/~pdw/iftop/ 二.iftop有什么用? iftop可以用来监 ...

  3. jQuery样式操作

    获取样式和设置样式 <p class='myClass'  title='this is p'>this is p</p> 样式其实就是class属性所以设置和获取样式都能用a ...

  4. 各种概念POJO、JAVABEAN、DAO、DTO、PO、VO、BO、SSH、EJB

    转自:https://my.oschina.net/pacoyang/blog/151695 POJO(pure old java object)是普通java类,有一些private的参数作为对象的 ...

  5. 训练1-J

    把一个偶数拆成两个不同素数的和,有几种拆法呢? Input 输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束. Output 对应每个偶数,输出其拆成不同素数的个数,每 ...

  6. 用户登录记住用户名导致表单自动填充bug解决方法

    最近做项目出现了一个极其讨厌的bug:在用户登录网站时,浏览器会自动提示是否记住密码,当选择记住密码时,正常浏览网页,会发现有那么几个input输入框会自动填充用户名,非常讨厌, 于是就觉得挺简单的一 ...

  7. applicationContext-redis.xml

    一.动态切换单机和集群 spring-redis 的配置 <!-- 连接redis单机版 --> <bean id="jedisClientPool" class ...

  8. Centos如何安装 jdk 环境变量

    一.编辑 profile 文件 vim /etc/profile 二.在 profile 文件下面最下面加上以下内容 export JAVA_HOME=/usr/local/java/jdk1.7.0 ...

  9. mysql查询优化--临时表和文件排序(Using temporary; Using filesort问题解决)

    先看一段sql: <span style="font-size:18px;">SELECT * FROM rank_user AS rankUser LEFT JOIN ...

  10. Shell编程入门(第二版)(上)

    简单的示例Shell程序 示例1. #!/bin/bash #This is to show what a shell script looks like echo "Our first e ...