zoukankan      html  css  js  c++  java
  • CF 558B(Amr and The Large Array-计数)

    B. Amr and The Large Array
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.

    Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.

    Help Amr by choosing the smallest subsegment possible.

    Input

    The first line contains one number n (1 ≤ n ≤ 105), the size of the array.

    The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.

    Output

    Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.

    If there are several possible answers you may output any of them.

    Sample test(s)
    input
    5
    1 1 2 2 1
    
    output
    1 5
    input
    5
    1 2 2 3 1
    
    output
    2 3
    input
    6
    1 2 2 1 1 2
    
    output
    1 5
    Note

    A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1


    对每一个可能值计数


    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<functional>
    #include<iostream>
    #include<cmath>
    #include<cctype>
    #include<ctime>
    using namespace std;
    #define For(i,n) for(int i=1;i<=n;i++)
    #define Fork(i,k,n) for(int i=k;i<=n;i++)
    #define Rep(i,n) for(int i=0;i<n;i++)
    #define ForD(i,n) for(int i=n;i;i--)
    #define RepD(i,n) for(int i=n;i>=0;i--)
    #define Forp(x) for(int p=pre[x];p;p=next[p])
    #define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
    #define Lson (x<<1)
    #define Rson ((x<<1)+1)
    #define MEM(a) memset(a,0,sizeof(a));
    #define MEMI(a) memset(a,127,sizeof(a));
    #define MEMi(a) memset(a,128,sizeof(a));
    #define INF (2139062143)
    #define F (100000007)
    #define MAXN (2000000+10)
    #define N (1000000)
    typedef long long ll;
    ll mul(ll a,ll b){return (a*b)%F;}
    ll add(ll a,ll b){return (a+b)%F;}
    ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}
    void upd(ll &a,ll b){a=(a%F+b%F)%F;}
    int l[MAXN],r[MAXN],t[MAXN],n;
    int main()
    {
    //	freopen("B.in","r",stdin);
    //	freopen(".out","w",stdout);
    	
    	For(i,N) l[i]=INF,r[i]=-INF,t[i]=0;
    	
    	cin>>n;
    	For(i,n)
    	{
    		int p;scanf("%d",&p);
    		l[p]=min(l[p],i);
    		r[p]=max(r[p],i);
    		t[p]++;
    	}
    	
    	int ma=0,ans=INF,j=0;
    	For(i,N) ma=max(ma,t[i]);
    	For(i,N)
    		if (ma==t[i]&&ans>r[i]-l[i]+1)
    		{
    			 ans=r[i]-l[i]+1;j=i;
    		}
    	cout<<l[j]<<' '<<r[j]<<endl;
    	
    	return 0;
    }
    





  • 相关阅读:
    php7 & lua 压测对比
    .NET CORE——Console中使用依赖注入
    EntityFramework Core 自动绑定模型映射
    月末总结与推书
    Dapper连接与事务的简单封装
    EntityFramework Core 学习扫盲
    从输入url到页面返回到底发生了什么
    [译]C#和.NET中的字符串
    利用C#迭代器的一个杨辉三角示例
    用 dotTrace 进行性能分析时,各种不同性能分析选项的含义和用途
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6811403.html
Copyright © 2011-2022 走看看