zoukankan      html  css  js  c++  java
  • Contest Hunter 1401 兔子与兔子

    1401 兔子与兔子 0x10「基本数据结构」例题

    描述

    很久很久以前,森林里住着一群兔子。有一天,兔子们想要研究自己的 DNA 序列。我们首先选取一个好长好长的 DNA 序列(小兔子是外星生物,DNA 序列可能包含 26 个小写英文字母),然后我们每次选择两个区间,询问如果用两个区间里的 DNA 序列分别生产出来两只兔子,这两个兔子是否一模一样。注意两个兔子一模一样只可能是他们的 DNA 序列一模一样。

    输入格式

    第一行一个 DNA 字符串 S。
    接下来一个数字 m,表示 m 次询问。
    接下来 m 行,每行四个数字 l1, r1, l2, r2,分别表示此次询问的两个区间,注意字符串的位置从1开始编号。
    其中 1 ≤ length(S), m ≤ 1000000

    输出格式

    对于每次询问,输出一行表示结果。如果两只兔子完全相同输出 Yes,否则输出 No(注意大小写)

    样例输入

    aabbaabb
    3
    1 3 5 7
    1 3 6 8
    1 2 1 2

    样例输出

    Yes
    No
    Yes
     1 //#pragma GCC optimize("O1")
     2 //#pragma GCC optimize("O2")
     3 //#pragma GCC optimize("O3")
     4 #include<cstdio>
     5 #include<cstring>
     6 #include<iostream>
     7 #include<algorithm>
     8 #include<ctime>
     9 #include<cmath>
    10 #include<vector>
    11 //#include<queue>
    12 //#include<stack>
    13 //#include<map>
    14 //#include<set>
    15 #define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
    16 #define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
    17 #define Ii inline int
    18 #define Iv inline void
    19 #define Il inline long long
    20 #define Ib inline bool
    21 #define INF 1<<31
    22 #define re register
    23 #define ll long long
    24 #define ull unsigned long long
    25 #define Max(a,b) ((a)>(b)?(a):(b))
    26 #define Min(a,b) ((a)<(b)?(a):(b))
    27 template<class Tp>Tp Cmax(Tp &a,Tp b){((a)=(a)>(b)?(a):(b));}
    28 template<class Tp>Tp Cmin(Tp &a,Tp b){((a)=(a)<(b)?(a):(b));}
    29 #define Fill(a,b) memset((a),(b),sizeof((a)))
    30 #define D_e_Line printf("
    -------------
    ")
    31 #define D_e(x) printf("
    ______%d_______
    ",x)
    32 #define Pause system("pause")
    33 #define lson l,mid,rt<<1
    34 #define rson mid+1,r,rt<<1|1
    35 using namespace std;
    36 const int N=1000005;
    37 struct ios{
    38     template<typename _Tp> inline ios operator>> (_Tp &x){
    39         x=0;int f=1;char c;
    40         for(c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
    41         while(c>='0'&&c<='9')x=x*10+(c^'0'),c=getchar();
    42         x*=f;
    43         return *this;
    44     }
    45     template<typename _Tp> inline ios operator<< (_Tp x){
    46         char s[66];int digit=0;
    47         if(x==0)putchar('0');
    48         if(x<0)x=-x,putchar('-');
    49         while(x)s[++digit]=x%10^'0',x/=10;
    50         nR(i,digit,1)putchar(s[i]);
    51         return *this;
    52     }
    53 }io;
    54 char str[N];
    55 ull f[N],p[N];
    56 const ull base=131;
    57 //#define int long long
    58 int main(){
    59     scanf("%s",str+1);
    60     int len=strlen(str+1);
    61     p[0]=1;
    62     R(i,1,len)
    63         f[i]=f[i-1]*base+((str[i]^'a')+1),
    64         p[i]=p[i-1]*base;
    65     int T;
    66     io>>T;
    67     while(T--){
    68         int l1,r1,l2,r2;
    69         io>>l1>>r1>>l2>>r2;
    70 //        scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
    71         if(f[r1]-f[l1-1]*p[r1-l1+1]==f[r2]-f[l2-1]*p[r2-l2+1])
    72             printf("Yes
    ");
    73         else
    74             printf("No
    ");
    75     }
    76     return 0;
    77 }
    View Code
     
  • 相关阅读:
    pipelinewise 学习二 创建一个简单的pipeline
    pipelinewise 学习一 docker方式安装
    Supercharging your ETL with Airflow and Singer
    ubuntu中使用 alien安装rpm包
    PipelineWise illustrates the power of Singer
    pipelinewise 基于singer 指南的的数据pipeline 工具
    关于singer elt 的几篇很不错的文章
    npkill 一个方便的npm 包清理工具
    kuma docker-compose 环境试用
    kuma 学习四 策略
  • 原文地址:https://www.cnblogs.com/bingoyes/p/10339915.html
Copyright © 2011-2022 走看看