zoukankan      html  css  js  c++  java
  • BZOJ3207 花神的嘲讽计划

    hash值建主席树。

    垃圾题面没有熟虑范围害我MLE——>RE。

    By:大奕哥

     1 #include<bits/stdc++.h>
     2 #define unll unsigned long long
     3 #define inf 18446744073709551615UL
     4 using namespace std;
     5 const int N=1000005;
     6 struct node{
     7     int l,r,s;
     8 }t[2000005];
     9 int a[N],rt[N],n,m,k,cnt;unll H[N],pos[N],num;
    10 void change(int &x,unll l,unll r,unll w)
    11 {
    12     t[++cnt]=t[x];x=cnt;
    13     if(l==r){
    14         t[x].s++;return;
    15     }
    16     int mid=l+r>>1;
    17     if(w<=mid)change(t[x].l,l,mid,w);
    18     else change(t[x].r,mid+1,r,w);
    19     t[x].s=t[t[x].l].s+t[t[x].r].s;
    20 }
    21 int query(int x,int y,unll l,unll r,unll w)
    22 {
    23     if(l==r)return t[x].s-t[y].s;
    24     unll mid=l+r>>1;
    25     if(w<=mid)return query(t[x].l,t[y].l,l,mid,w);
    26     else return query(t[x].r,t[y].r,mid+1,r,w);
    27 }
    28 int main()
    29 {
    30     scanf("%d%d%d",&n,&m,&k);unll base=1;
    31     for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    32     for(int i=1;i<=k;++i)base*=107;
    33     for(int i=1;i<=n;++i)
    34     {
    35         H[i]=H[i-1]*107+a[i];
    36         pos[++num]=H[i]-H[i-k]*base;
    37     }
    38     sort(pos+1,pos+1+num);num=unique(pos+1,pos+1+num)-pos-1;
    39     for(int i=k;i<=n;++i)
    40     rt[i]=rt[i-1],change(rt[i],1,num,lower_bound(pos+1,pos+1+num,H[i]-H[i-k]*base)-pos);
    41     int l,r,x; unll w;
    42     for(int i=1;i<=m;++i)
    43     {
    44         scanf("%d%d",&l,&r);w=0;
    45         for(int j=1;j<=k;++j)
    46         {
    47             scanf("%d",&x);
    48             w=w*107+x;
    49         }
    50         int p=lower_bound(pos+1,pos+1+num,w)-pos;
    51         if(pos[p]!=w)puts("Yes");
    52         else if(query(rt[r],rt[l+k-2],1,num,p))puts("No");
    53         else puts("Yes");
    54     }
    55     return 0;
    56 }
  • 相关阅读:
    xcode
    2020上班第一天
    动态网页爬取方法
    静态网页爬虫获取数据的简单方法Xpath
    帆软9.0升级10.0(摘自帆软官方文档)
    linux下安装redis
    linux 命令笔记
    shell 编写mongodb linux下安装脚本
    pl/sql基础之三
    plsql基础二之集合
  • 原文地址:https://www.cnblogs.com/nbwzyzngyl/p/8438363.html
Copyright © 2011-2022 走看看