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;
    }
    





  • 相关阅读:
    C# 寻找数组中的最大子数组
    C# 求两个矩阵相交面积
    C# 排序方法
    oracleI基础入门(8)tableINTERSECT Crazy
    oracleI基础入门附(2)算总合百分比,算累积总合百分比 Crazy
    oracleI基础入门附(1)算中位数,算累积总计 Crazy
    oracleI基础入门(9)table子查询 Crazy
    oracleI基础入门(10)EXISTS Crazy
    oracleI基础入门(11)case Crazy
    oracleI基础入门(8)tableMINUS Crazy
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6811403.html
Copyright © 2011-2022 走看看