• 2016"百度之星"


    链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1001
    我用线段树过的~可能要注意a,b的关系
     1 #include<stdio.h>
     2 //#include<bits/stdc++.h>
     3 #include<string.h>
     4 #include<iostream>
     5 #include<math.h>
     6 #include<sstream>
     7 #include<set>
     8 #include<queue>
     9 #include<map>
    10 #include<vector>
    11 #include<algorithm>
    12 #include<limits.h>
    13 #define inf 0x7fffffff
    14 #define INFL 0x7fffffffffffffff
    15 #define lson l,m,rt<<1
    16 #define rson m+1,r,rt<<1|1
    17 #define LL long long
    18 #define ULL unsigned long long
    19 const int N = 200005;
    20 const int MOD = 9973;
    21 using namespace std;
    22 int num[N];
    23 int ans;
    24 char c[N];
    25 struct node
    26 {
    27     int left;
    28     int right;
    29     int value;
    30 }tree[N*4];
    31 void sum(int rt)
    32 {
    33     tree[rt].value = (tree[rt*2].value*tree[rt*2+1].value)%MOD;
    34 }
    35 void build(int l,int r,int rt)
    36 {
    37     tree[rt].left=l;
    38     tree[rt].right=r;
    39     int m=(l+r)>>1;
    40     if(l==r)
    41     {
    42         tree[rt].value=num[l];
    43         return;
    44     }
    45     build(lson);
    46     build(rson);
    47     tree[rt].value=(tree[rt*2].value*tree[rt*2+1].value)%MOD;
    48 }
    49 void query(int l,int r,int rt)
    50 {
    51     if(l==tree[rt].left&&r==tree[rt].right)
    52     {
    53         ans=(ans*tree[rt].value)%MOD;
    54         return ;
    55     }
    56     int m=(tree[rt].left+tree[rt].right)>>1;
    57      if(r<=m)
    58         query(l,r,rt*2);
    59     else if(l>m)
    60         query(l,r,rt*2+1);
    61     else
    62     {
    63         query(l,m,rt*2);
    64         query(m+1,r,rt*2+1);
    65     }
    66 }
    67 int main()
    68 {
    69     int t;
    70     while(~scanf("%d",&t))
    71     {
    72         scanf("%s",c);
    73         int len=strlen(c);
    74         for(int i=0;i<len;i++)
    75         {
    76             num[i+1]=c[i]-28;
    77         }
    78         build(1,N,1);
    79         for(int i=0;i<t;i++)
    80         {
    81             ans=1;
    82             int l,r;
    83             scanf("%d%d",&l,&r);
    84             if(l>r)
    85             {
    86                 swap(l,r);
    87             }
    88             query(l,r,1);
    89             printf("%d
    ",ans);
    90         }
    91     }
    92     return 0;
    93 }
  • 相关阅读:
    mysql find_int_set
    PHPSTROM8.0 注册码(7.1也可用)
    gym 101657 D
    gym101657 C
    poj 3525
    poj1279
    poj3335
    poj 1228
    poj 1873
    poj 2074
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5494582.html
Copyright © 2020-2023  润新知