2057 The manager's worry(树状数组)
来源:互联网 发布:软件培训怎么样 编辑:程序博客网 时间:2024/06/05 17:10
@(K ACMer)
题意:
单点更新,区间查寻素数个数.
分析:
构造一个树状数组就可以了,定义sum[i]为
#include <iostream>#include <cstdio>#include <cstring>#include <set>#include <map>#include <stack>#include <vector>#include <string>#include <queue>#include <cstdlib>#include <cmath>#include <algorithm>using namespace std;const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e6 + 40;int bit[maxn], n, k, m, a[maxn];bool isprime(int x) { if (x <= 1) return false; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true;}void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; }}int sum(int i) { int sum = 0; while (i > 0) { sum += bit[i]; i -= i & -i; } return sum;}int main(void) { int T = 1; while (scanf("%d%d%d", &n, &k, &m), n * n + k * k + m * m) { printf("CASE #%d:\n", T++); int t = isprime(m) ? 1 : 0; memset(bit, 0, sizeof(bit)); for (int i = 1; i <= n; i++) { a[i] = m; if (t) add(i, 1); } while (k--) { int x, y, z; scanf("%d%d%d", &x, &y, &z); if (!x) { bool f = isprime(a[y]), s = isprime(a[y] + z); a[y] += z; if (f && !s) add(y, -1); if (!f && s) add(y, 1); } else { printf("%d\n", sum(z) - sum(y - 1)); } } puts(""); } return 0;}
0 0
- 2057 The manager's worry(树状数组)
- what's worry me?
- worry
- 【树状数组】PKU-2057-The Lost House
- 树状数组求第K小值 (spoj227 Ordering the Soldiers && hdu2852 KiKi's K-Number)
- 树状数组&&Color the ball
- (树状数组)Color the ball
- Enterprise Security: The Manager's Defense Guide
- The Product Manager's Handbook [Part 1]
- The Product Manager's Handbook [Part 2]
- HDU 5592 ZYB's Permutation(树状数组)
- HDU5592 ZYB's Premutation(树状数组)
- hdu3966Aragorn's Story【树链剖分+树状数组】
- HDU5592 ZYB's Premutation 树状数组应用
- HDU 1556 color the ball 树状数组
- hoj 2430 Counting the algorithms +树状数组
- SPOJ 227 Ordering the Soldiers (树状数组)
- hdu 1556 Color the ball (树状数组)
- PJSIP 添加视频的思路和想法
- 开源内存数据库H2 实现单元测试用例的独门独户
- JS日期选择器
- 自定义的字符串类
- 【翻译】利用加速度求解位置的算法——三轴传感器
- 2057 The manager's worry(树状数组)
- (仿360卸载后弹窗)Android卸载程序之后跳转到指定的反馈页面
- 素数求和问题
- Redis键值设计
- LoadRunner监控Linux资源
- Linux下搭建FTP服务器
- ASP.NET身份验证——Windows身份认证
- 5个Xcode开发调试技巧
- libsvm在matlab和Python上的探索