• 【BZOJ 2724】 2724: [Violet 6]蒲公英 (区间众数不带修改版本)


     

    2724: [Violet 6]蒲公英

    Time Limit: 40 Sec  Memory Limit: 512 MB
    Submit: 1908  Solved: 678

    Description

    Input

    修正一下

    l = (l_0 + x - 1) mod n + 1, r = (r_0 + x - 1) mod n + 1

    Output

    Sample Input

    6 3
    1 2 3 2 1 2
    1 5
    3 6
    1 5

    Sample Output

    1
    2
    1

    HINT


    修正下:


    n <= 40000, m <= 50000

    Source

    【分析】

      区间众数见:http://www.docin.com/p-679227660.html

      

      

       我这道题的就是打这个做法【实际上是膜hzwer的代码

      【关于[l,r]之间有多少个x,是把位置存在数值的vector里面,然后lower_bound(l)~upper_bound(r)有多少个数

      然后分块一下就好了。

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<vector>
     8 #include<map>
     9 using namespace std;
    10 #define Maxn 50010
    11 #define Maxm 510
    12 
    13 int a[Maxn],f[Maxn],bl[Maxn],mode[Maxm][Maxm];
    14 map<int,int> mp;int id;
    15 vector<int > v[Maxn];
    16 
    17 int blo,n;
    18 int cnt[Maxn];
    19 void pre(int x)
    20 {
    21     memset(cnt,0,sizeof(cnt));
    22     int mx=0,ans=0;
    23     for(int i=(x-1)*blo+1;i<=n;i++)
    24     {
    25         cnt[a[i]]++;
    26         int t=bl[i];
    27         if(cnt[a[i]]>mx||(cnt[a[i]]==mx&&f[a[i]]<f[ans]))
    28             ans=a[i],mx=cnt[a[i]];
    29         mode[x][t]=ans;
    30     }
    31 }
    32 
    33 int get_(int l,int r,int x)
    34 {
    35     return upper_bound(v[x].begin(),v[x].end(),r)-lower_bound(v[x].begin(),v[x].end(),l);
    36 }
    37 
    38 int query(int l,int r)
    39 {
    40     int ans,mx=0;
    41     if(bl[l]==bl[r])
    42     {
    43         for(int i=l;i<=r;i++)
    44         {
    45             int t=get_(l,r,a[i]);
    46             if(t>mx||(t==mx)&&f[a[i]]<f[ans]) ans=a[i],mx=t;
    47         }
    48     }
    49     else
    50     {
    51         ans=mode[bl[l]+1][bl[r]-1],mx=get_(l,r,ans);
    52         for(int i=l;i<=bl[l]*blo;i++)
    53         {
    54             int t=get_(l,r,a[i]);
    55             if(t>mx||(t==mx)&&f[a[i]]<f[ans]) ans=a[i],mx=t;
    56         }
    57         for(int i=(bl[r]-1)*blo+1;i<=r;i++)
    58         {
    59             int t=get_(l,r,a[i]);
    60             if(t>mx||(t==mx&&f[a[i]]<f[ans])) ans=a[i],mx=t;
    61         }
    62     }
    63     return ans;
    64 }
    65 
    66 int main()
    67 {
    68     int m;
    69     scanf("%d%d",&n,&m);
    70     blo=200;
    71     int ans=0;id=0;
    72     for(int i=1;i<=n;i++)
    73     {
    74         scanf("%d",&a[i]);
    75         if(!mp[a[i]]) mp[a[i]]=++id,f[id]=a[i];
    76         a[i]=mp[a[i]];
    77         v[a[i]].push_back(i);
    78     }
    79     for(int i=1;i<=n;i++) bl[i]=(i-1)/blo+1;
    80     for(int i=1;i<=bl[n];i++) pre(i);
    81     for(int i=1;i<=m;i++)
    82     {
    83         int l,r;
    84         scanf("%d%d",&l,&r);
    85         l=(l+ans-1)%n+1,r=(r+ans-1)%n+1;
    86         if(l>r) swap(l,r);
    87         ans=f[query(l,r)];
    88         printf("%d
    ",ans);
    89     }
    90     return 0;
    91 }
    View Code

    【不行了 我也用map了。。。。

      然后其实有更快的方法,然后我尝试了一下就放弃了。。【感觉是用空间和代码量换时间啊好恶心、、

      

       

    然后带修改这样【其实我没看。。

     2017-04-23 21:21:48

  • 相关阅读:
    (2)远程管理线上服务之sshd服务
    (1)远程管理线上服务之sshd服务
    自建yum仓库
    CentOS7安装MySQL报错Failed to start mysqld.service: Unit not found解决办法
    ssh(Spring,Struts2,Hibernate)注解版整合
    Hibernate关联映射(多对一,一对多, 一些属性(Cascade,inverse,order by))
    HQL查询(分页查询,动态sql查询,参数查询)
    初识Oracle
    ajax获取属性值
    关于SpringMvc返回值类型 Object使用
  • 原文地址:https://www.cnblogs.com/Konjakmoyu/p/6754080.html
Copyright © 2020-2023  润新知