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. F5 datasheet

  2. jemeter参数化读取文件

    1.新建一个123.csv文件 如图 2.添加http请求 3.添加一个查看结果树 二.通过函数助手 (1)打开函数助手 ......... 在json属组中引入变量  这是别人参考的

  3. input标签处理多文件上传

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  4. NOI 2016 循环之美 (莫比乌斯反演+杜教筛)

    题目大意:略 洛谷传送门 鉴于洛谷最近总崩,附上良心LOJ链接 任何形容词也不够赞美这一道神题 $\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{M}[gcd(i,j) ...

  5. 项目工程的包package与文件夹的关系

    项目工程的包package与文件夹的关系: 1. 包名与文件夹是分层关系,包名只是一个字符串而已,包名.对应的是层级的文件夹. 如,com.Immoc.Access包,只是一个字符串.但他对应的win ...

  6. HDU 3709

    真是跪了,一看范围就不会往枚举的方向想,没想到真用枚举加剪枝了...->——-> 解释一下代码中的上限: 例如4567,当枚举最高位时,很明显不能超过4,所以有上限,但当最高位为3以下时, ...

  7. 用opencv实现的PCA算法,非API调用

    理论參考文献:但此文没有代码实现.这里自己实现一下,让理解更为深刻 问题:如果在IR中我们建立的文档-词项矩阵中,有两个词项为"learn"和"study",在 ...

  8. hdu1181(变形课)

    点击打开链接 Problem Description 呃......变形课上Harry碰到了一点小麻烦,由于他并不像Hermione那样可以记住全部的咒语而任意的将一个棒球变成刺猬什么的,可是他发现了 ...

  9. hdu 5410 CRB and His Birthday 01背包和全然背包

    #include<stdio.h> #include<string.h> #include<vector> #include<queue> #inclu ...

  10. MYSQL Training: MySQL I

    让以admin身份登录.源代码: 非常easy的注入 在username输入 admin' OR '1'='1 OK.