2016"百度之星" - 资格赛(Astar Round1)Problem A 线段树区间查询
来源:互联网 发布:合肥组装电脑淘宝 编辑:程序博客网 时间:2024/06/06 12:42
Problem A
Accepts: 1829
Submissions: 12436
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
以每个位置字母的哈希值为叶子节点向上建立线段树,然后区间查询即可
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1using namespace std;const int maxn = 100000, mod = 9973;int sum[maxn << 2], cnt, len;char s[maxn + 10];void PushUp(int rt) {sum[rt] = ((sum[rt << 1] % mod) * (sum[rt << 1 | 1] % mod)) % mod;}void build(int l, int r, int rt) {if (l == r) {sum[rt] = ((int)s[++cnt] - 28) % mod;return;}int m = (l + r) >> 1;build(lson);build(rson);PushUp(rt);}int query(int L, int R, int l, int r, int rt) {if (L <= l && r <= R) {return sum[rt];}int m = (l + r) >> 1;int res = 1;if (L <= m) {res *= (query(L, R, lson) % mod);}if (R > m) {res *= (query(L, R, rson) % mod);}return res % mod;}int main(){int N;while (~scanf("%d", &N)) {scanf("%s", s + 1);cnt = 0;len = strlen(s + 1);build(1, len, 1);for (int t = 1; t <= N; t++) {int x, y;scanf("%d%d", &x, &y);printf("%d\n", query(x, y, 1, len, 1));}}return 0;}
0 0
- 2016"百度之星" - 资格赛(Astar Round1)Problem A 线段树区间查询
- 2016"百度之星" - 资格赛(Astar Round1)Problem A
- hdu 5685 Problem A(2016"百度之星" - 资格赛(Astar Round1)——线段树)
- 2016"百度之星" - 资格赛(Astar Round1)Problem B
- 2016"百度之星" - 资格赛(Astar Round1) Problem D
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- 2016"百度之星" - 资格赛(Astar Round1) Problem D
- 2016"百度之星" - 资格赛(Astar Round1)Problem D
- 2016"百度之星" - 资格赛(Astar Round1)Problem B
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- 2016"百度之星" - 资格赛(Astar Round1)Problem D
- Problem B 2016"百度之星" - 资格赛(Astar Round1)
- Problem D 2016"百度之星" - 资格赛(Astar Round1)
- 2016"百度之星" - 资格赛(Astar Round1)Problem A(快速幂+逆元)
- Problem A(逆元) 2016"百度之星" - 资格赛(Astar Round1)
- 2016"百度之星" - 资格赛(Astar Round1)Problem A (乘法逆元)
- 2016"百度之星" - 资格赛(Astar Round1)Problem A (乘法逆元)
- 2016"百度之星" - 资格赛(Astar Round1)Problem A B C D--java代码
- 写文献综述的二十八个要点
- 备忘录
- 数据库的设计范式
- Android 开发笔记(准备工作)
- UVA100
- 2016"百度之星" - 资格赛(Astar Round1)Problem A 线段树区间查询
- Android学习笔记十五:wifi连接,获取名字,IP地址
- TextView整理
- MSSQL之六 数据库设计
- 异常处理注意点
- crawler4j源码解析
- Linux 安装svn
- Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be
- 第12周-阅读程序(1)