题目链接:acm.hdu.edu.cn/showproblem.php?pid=5685
2 ACMlove2015 1 11 8 10 1 testMessage 1 1
6891 9240 88
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define N 1000010 #define ll long long #define Mod 9973 char ch[N]; struct node { int l,r; ll ans; } s[N*8]; void init(int l,int r,int k) { s[k].l=l; s[k].r=r; s[k].ans=1; if (l==r) { s[k].ans=s[k].ans*(ch[l]-28)%Mod; return ; } int mid=(l+r)/2; init(l,mid,2*k); init(mid+1,r,2*k+1); s[k].ans=(s[k*2].ans*s[k*2+1].ans)%Mod; } int Search(int l,int r,int k) { if(s[k].l==l&&s[k].r==r) return s[k].ans; int mid=(s[k].l+s[k].r)/2; if (l>mid) return Search(l,r,2*k+1); else if (r<=mid) return Search(l,r,2*k); else return (Search(mid+1,r,2*k+1)*Search(l,mid,2*k))%Mod; } int main() { int n,a,b; ll as; while (~scanf("%d",&n)) { scanf("%s",ch); int len=strlen(ch); init(0,len-1,1); for (int i=0; i<n; i++) { scanf("%d%d",&a,&b); if (a>b||a>len||b>len||b<=0||a<=0) { printf ("%lld\n",as); continue; } as=Search(a-1,b-1,1); printf ("%lld\n",as); } } return 0; }