2016"百度之星" - 资格赛(Astar Round1)
http://acm.hdu.edu.cn/showproblem.php?pid=5685
// 一看就是线段树
// (a*b)%c=(a%c*b%c)%c;
//没什么好说的直接上代码
#include<stdio.h> #include<string.h> #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 char str[100010]; int tree[100010*4]; void pushup(int rt) { tree[rt]=(tree[rt<<1]*tree[rt<<1|1])%9973; } void build(int l,int r,int rt) { tree[rt]=1; if(l==r) {tree[rt]=str[l];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 tree[rt]; int m=(l+r)>>1; int ret=1; if(L<=m) ret*=query(L,R,lson); if(R>m) ret*=query(L,R,rson); return ret%9973; } int main() { int t; while(~scanf("%d",&t)) { int n=t; scanf("%s",str+1); int len=0; for(int i=1;str[i]!='\0';i++) len++; for(int i=1;str[i]!='\0';i++) str[i]=(str[i]-28)%9973; build(1,len,1); int a,b; while(n--) { scanf("%d%d",&a,&b); printf("%d\n",query(a,b,1,len,1)); } } return 0; }