ZOJ 3886 Nico Number
来源:互联网 发布:修改apk软件版本号 编辑:程序博客网 时间:2024/05/02 02:57
Description
Kousaka Honoka and Minami Kotori are playing a game about a secret of Yazawa Nico.
When the game starts, Kousaka Honoka will give Minami Kotori an array A of N non-negative integers. There is a special kind of number in the array, which is called NicoNico-number. We call a integer x is a NicoNico-number, if all integers(no more than x) that is coprime with x could form an Arithmetic Sequence.Then Minami Kotori will choose some consecutive part of the array A, wondering the number of NicoNico-number in this part. What's more, Kousaka Honoka sometimes modify the value of some consecutive elements in the array. Now it is your task to simulate this game!Input
There are multiple test cases in input, you should process to the end of file.
For each case, the first line is an integer N, the number of elements in the array described above. Then second line contains N integers no greater than 107, the elements of the array initially.(1 <= N <= 100,000)
The third line is a integer T, the number of the operations of the game. Each line of the following T lines is in one of the following formats.(1 <= T <= 100,000)
"1 L R" : Minami Kotori will chooses the consecutive part of the array from the Lth to Rth element inclusive. (1 <= L <= R <= N)
"2 L R v" : Kousaka Honoka will change the value of the pth element A[p] in the array to A[p]%v for all L <= p <= R.(1 <= L <= R <= N, 1 <= v <= 107)
"3 p x" : Kousaka Honoka will change the value of the p th element A[p] to x.(1 <= p <= N, 1 <= x <= 107)
Output
Each time when Minami Kotori chooses some part of the array, you should output a line, the number of NicoNico-number in that part.
Sample Input
34 6 961 1 31 3 32 1 1 101 1 33 2 41 1 3
Sample Output
2022
Hint
4 is a NicoNico-number because only 1 and 3 is coprime with 4 among the integers no greater than 4, and could form an Arithmetic Sequence {1,3}.
先确定有哪些niconico数,然后对于mod运算每次至少/2
线段树暴力更新即可。
#include<cstdio>#include<vector>#include<cmath>#include<map>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const LL maxn = 400005;int T, n, m, x, y, z, ans;int f[maxn], sum[maxn], M[(int)1e7 + 7], p[(int)1e7 + 7];inline void read(int &ret){char c;do {c = getchar();} while (c < '0' || c > '9');ret = c - '0';while ((c = getchar()) >= '0' && c <= '9')ret = ret * 10 + (c - '0');}void pre(){int tot = 0;for (int i = 2; i <= 1e7; ++i){if (!M[i]) p[tot++] = i;for (int j = 0; j < tot; ++j){if (i*p[j]>1e7) break;M[i*p[j]] = 1;if (i%p[j] == 0) break;}}M[6] = 0;for (int i = 1; i <= 1e7; i <<= 1) M[i] = 0;}void build(int now, int l, int r){if (l == r){scanf("%d", &f[now]);sum[now] = M[f[now]];}else{int mid = (l + r) >> 1;build(now + now, l, mid);build(now + now + 1, mid + 1, r);f[now] = max(f[now + now], f[now + now + 1]);sum[now] = sum[now + now] + sum[now + now + 1];}}void change(int now, int l, int r, int ll, int rr, int v){if (v > f[now]) return;if (l == r) { f[now] = f[now] % v; sum[now] = M[f[now]]; }else{int mid = (l + r) >> 1;if (ll <= mid) change(now + now, l, mid, ll, rr, v);if (rr > mid) change(now + now + 1, mid + 1, r, ll, rr, v);f[now] = max(f[now + now], f[now + now + 1]);sum[now] = sum[now + now] + sum[now + now + 1];}}void change(int now, int l, int r, int one, int v){if (l == r) { f[now] = v; sum[now] = M[f[now]]; }else{int mid = (l + r) >> 1;if (one <= mid) change(now + now, l, mid, one, v);if (one > mid) change(now + now + 1, mid + 1, r, one, v);f[now] = max(f[now + now], f[now + now + 1]);sum[now] = sum[now + now] + sum[now + now + 1];}}void get(int now, int l, int r, int ll, int rr){if (l >= ll&&r <= rr) ans += sum[now];else{int mid = (l + r) >> 1; if (ll <= mid) get(now + now, l, mid, ll, rr);if (rr > mid) get(now + now + 1, mid + 1, r, ll, rr);}}int main(){//read(T);pre();while (scanf("%d", &n) == 1){build(1, 1, n);scanf("%d", &m);while (m--){scanf("%d", &x);if (x == 2){scanf("%d%d%d", &x, &y, &z);change(1, 1, n, x, y, z);}else if (x == 3) { scanf("%d%d", &y, &z); change(1, 1, n, y, z); }else{ans = 0;scanf("%d%d", &y, &z);get(1, 1, n, y, z);printf("%d\n", z + 1 - y - ans);}}}return 0;}
- ZOJ 3886 Nico Number
- ZOJ 3886 Nico Number (线段树)
- 【ZOJ】3886 Nico Number【线段树】
- ZOJ 3886 Nico number(线段树)
- ZOJ 3886 Nico Number(素数筛选 + 线段树)
- zoj 3886 Nico Number(线段树,区间取模操作)
- ZOJ 3886 Nico Number(线段树单点更新+找规律)
- ZOJ 3886 Nico Number(筛素数+Love(线)Live(段)树)
- zoj3886.Nico Number
- zoj2886 Nico Number
- ZOJ3886-Nico Number
- zoj3886--Nico Number(素数筛+线段树)
- ZOJ3886 2015July月赛 F-Nico Number(线段树)
- Nico Website
- ZOJ 1039 Number Game
- zoj 1526 Big Number
- ZOJ 2829 Beautiful Number
- zoj 2105 Number Sequence
- 最小费用最大流
- 自己动手写贝叶斯分类器给图书分类
- 我的Android进阶之旅------>MIME类型大全
- 多维数组的动态分配(二三维)
- javac和java
- ZOJ 3886 Nico Number
- 自己动手实现一个队列LGQueue(刚刚)
- HNUST 1581 聚宝盆
- javascript不能支持函数的重载
- ios开发特殊符号大全:字符+键盘符...
- Netty入门教程
- RHEL十二(安装和更新软件包)
- tableView下面多余显示的Cell去除方法
- 使用Maven构建Web应用(上)