#include #include #include using namespace std; inline void print(int pt) { printf("%d\n", pt); } inline void print(long long pt) { printf("%I64d\n", pt); } inline void print(double pt) { printf("%f\n", pt); } inline void print(char pt[]) { printf("%s\n", pt); } inline void print(char pt) { printf("%c\n", pt); } inline void scan(int &pt) { scanf("%d", &pt); } inline void scan(long long &pt) { scanf("%I64d", &pt); } inline void scan(double &pt) { scanf("%lf", &pt); } inline void scan(char pt[]) { scanf("%s", pt); } struct pii { int a; int b; friend int operator<(pii a, pii b) { if (a.a != b.a) return a.a < b.a; return a.b < b.b; } }; struct piii { int quest; int time; int index; friend int operator<(piii a, piii b) { if (a.quest != b.quest) return a.quest > b.quest; return a.time < b.time; } }; class str { public: char strr[30]; str() { memset(strr, 0, sizeof(strr)); } friend int operator<(str a, str b) { return strcmp(a.strr, b.strr) < 0; } friend int operator==(str a, str b) { int lena = sizeof(a.strr) / sizeof(char); for (int i = 0; i < lena; i++) { if (a.strr[i] != b.strr[i]) return 0; } return 1; } }; int bits[50]; void getbits() { for (int i = 0; i < 50; i++) { bits[i] = 1 << i; } } long long HASH = 1414732762971465ll; struct pp { int nums[200]; long long gethash() { long long a = 0; for (int i = 0; i < 200; i++) { a *= 40; a += nums[i]; a %= HASH; } return a; } pp() { memset(nums, 0, sizeof(nums)); } friend int operator<(pp a, pp b) { for (int i = 0; i < 200; i++) { if (a.nums[i] != b.nums[i]) return a.nums[i] < b.nums[i]; } return 0; } }; char stra[100050]; #define maxn 100050 int iiii; class SegmentTree { public: class Node { public: int left, right, sum; Node() { left = 0; right = 0; sum = 1; } int mid() { return (left + right) >> 1; } }; Node tree[maxn * 4]; int len; void btree(int left, int right, int rt) { tree[rt].left = left; tree[rt].right = right; if (left == right) { // scanf("%d", &tree[rt].sum); tree[rt].sum = stra[iiii] - 28; iiii++; return; } int mid = tree[rt].mid(); btree(left, mid, rt << 1); btree(mid + 1, right, rt << 1 | 1); tree[rt].sum = tree[rt << 1].sum * tree[rt << 1 | 1].sum % 9973; } void query(int left, int right, int rt, int L, int R, int& ans) { if (L <= left && right <= R) { ans *= tree[rt].sum; ans %= 9973; return; } int mid = tree[rt].mid(); if (R <= mid) query(left, mid, rt << 1, L, R, ans); else if (L > mid) query(mid + 1, right, rt << 1 | 1, L, R, ans); else { query(left, mid, rt << 1, L, R, ans); query(mid + 1, right, rt << 1 | 1, L, R, ans); } } //求L到R项的和(两端包括,并且Llen = len; btree(1, len, 1); } //返回数组的第index位. //只能做输出,不能用这个赋值!! //(因为要做成能赋值的话,得多花很多代码量,所以ACM中没什么实用价值) int operator[](int index) { return sum(index, index); } }; SegmentTree ST; int n,m; int main() { int left, right; int ansa; while (scanf("%d", &n) != EOF) { scan(stra); // ST = SegmentTree(); m = strlen(stra); ST.initialize(m + 5); for (int i = 0; i < n; i++) { scan(left); scan(right); if (left > right) swap(left, right); if (left < 1 || right > m) { print(ansa); continue; } print(ST.sum(left, right)); } } return 0; }