<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水題

      C. Dominated Subarray

      Let's call an array ?? dominated by value ?? in the next situation.

      At first, array ?? should have at least 2 elements. Now, let's calculate number of occurrences of each number ?????? in ?? and define it as ??????(??????). Then ?? is dominated (by ??) if (and only if) ??????(??)>??????(??′) for any other number ??′. For example, arrays [1,2,3,4,5,2], [11,11] and [3,2,3,2,3] are dominated (by 2, 11 and 3 respectevitely) but arrays [3], [1,2] and [3,3,2,2,1] are not.

      Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either dominated or not.

      You are given array ??1,??2,…,????. Calculate its shortest dominated subarray or say that there are no such subarrays.

      The subarray of ?? is a contiguous part of the array ??, i.?e. the array ????,????+1,…,???? for some 1≤??≤??≤??.

      Input

      The first line contains single integer ?? (1≤??≤1000) — the number of test cases. Each test case consists of two lines.

      The first line contains single integer ?? (1≤??≤2?105) — the length of the array ??.

      The second line contains ?? integers ??1,??2,…,???? (1≤????≤??) — the corresponding values of the array ??.

      It's guaranteed that the total length of all arrays in one test doesn't exceed 2?105.

      Output

      Print ?? integers — one per test case. For each test case print the only integer — the length of the shortest dominated subarray, or ?1 if there are no such subarrays.

      Example

      input
      4
      1
      1
      6
      1 2 3 4 5 1
      9
      4 1 2 4 5 4 3 2 1
      4
      3 3 3 3
      output
      -1
      6
      3
      2

      Note

      In the first test case, there are no subarrays of length at least 2, so the answer is ?1.

      In the second test case, the whole array is dominated (by 1) and it's the only dominated subarray.

      In the third test case, the subarray ??4,??5,??6 is the shortest dominated subarray.

      In the fourth test case, all subarrays of length more than one are dominated.

      題意

      現在定義一個Dominated number,表示這個序列中這個數字出現最多。

      現在給n個數,你需要找到一個最短的區間,使得這個區間里面存在唯一一個出現次數最多的數。

      題解

      其實思考思考,我們會發現出現最多的就是出現兩個而已。

      那么我們就暴力枚舉每一個數,看上一個數在哪個位置即可,然后選擇最短的就行。

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      const int maxn = 200005;
      int n,a[maxn],c[maxn];
      void solve(){
      	cin>>n;
      	int mx = 9999999;
      	for(int i=1;i<=n;i++){
      		c[i]=0;
      	}
      	for(int i=1;i<=n;i++){
      		cin>>a[i];
      		if(c[a[i]]!=0){
      			mx=min(i-c[a[i]]+1,mx);
      		}
      		c[a[i]]=i;
      	}
      	if(mx==9999999){
      		cout<<"-1"<<endl;
      	}else{
      		cout<<mx<<endl;
      	}
      }
      int main(){
      	int t;cin>>t;
      	while(t--)solve();
      }
      
      posted @ 2019-11-14 18:01  qscqesze  閱讀(483)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产色婷婷亚洲99精品小说| 国产人妻人伦精品婷婷| 古交市| 中文字幕丰满伦子无码ab| 亚洲乱码中文字幕小综合| 人妻系列无码专区无码中出| 在线一区二区中文字幕| 亚洲精品中文字幕二区| 国产亚洲999精品AA片在线爽| 乌苏市| 人人妻人人爽人人添夜夜欢视频| 99久久无码私人网站| 放荡的少妇2欧美版 | 亚洲va中文字幕无码久久不卡| 亚洲日本精品一区二区| 国产偷国产偷亚洲清高动态图| 日韩老熟女av搜索结果| 亚洲高清 一区二区三区| 亚洲欧美日韩综合久久| 中文字幕日韩精品有码| 国产精品中出一区二区三区| 又爆又大又粗又硬又黄的a片| 国产综合色在线精品| 风韵丰满妇啪啪区老老熟女杏吧| 亚洲午夜无码久久久久蜜臀AV | 国产精品制服丝袜无码| 九九九精品成人免费视频小说| 久久午夜无码鲁丝片直播午夜精品| 久久夜色撩人精品国产av| 猫咪社区免费资源在线观看| 日韩有码中文在线观看| 亚洲日本精品国产第一区| 日本丰满少妇高潮呻吟| 日本熟妇XXXX潮喷视频| 午夜高清国产拍精品福利| 日本熟妇色xxxxx日本免费看| 五月丁香啪啪| 湘潭县| 一区二区丝袜美腿视频| 国产一区二区精品自拍| 亚洲成人资源在线观看|