558B - Amr and The Large Array - CodeForces Solution


implementation *1300

Please click on ads to support us..

Python Code:

n = int(input())
l, r = 1, n
a = list(map(int, input().split()))
dd = dict()
for idx, i in enumerate(a):
    try:
        dd[i] = (dd[i][0]+1, dd[i][1], idx+1, max(dd[i][3], idx+1 - dd[i][1]))
    except:
        dd[i] = (1, idx+1, idx+1, 0)

d = n
mx = max(dd.values())[0]
temp = [i for i in dd.values() if i[0] == mx]
m_d = sorted(temp, key=lambda x: x[3])
temp_1 = [i for i in temp if i[3] == m_d[0][3]]
_, l, r, _ = temp_1[0]
print(l, r)

C++ Code:

#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
void solve();
#pragma GCC optimize("Ofast","inline","-ffast-math")
const int N = 101000;
int n, mx, d[N], dk[N * 10], firs[N * 10], last[N * 10];
int main(){
    // int t = 1; cin >> t;
    // while(t-- > 0) solve();
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> d[i];
        dk[d[i]]++;
        mx = max(mx, dk[d[i]]);
        if(!firs[d[i]]) firs[d[i]] = i;
        last[d[i]] = i;
    } int res = N, cur1, cur2;
    for(int i = 1; i < N * 10; i++){
        if(dk[i] == mx)
            if(res > last[i] - firs[i] + 1){
                res = last[i] - firs[i] + 1;
                cur1 = firs[i]; cur2 = last[i];
            }
    } cout << cur1 << " " << cur2;
}
const int fastIO = [](){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    return 0;
}();


Comments

Submit
0 Comments
More Questions

1519A - Red and Blue Beans
466A - Cheap Travel
659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream
1358D - The Best Vacation
1620B - Triangles on a Rectangle
999C - Alphabetic Removals
1634C - OKEA
1368C - Even Picture
1505F - Math
1473A - Replacing Elements
959A - Mahmoud and Ehab and the even-odd game
78B - Easter Eggs
1455B - Jumps
1225C - p-binary
1525D - Armchairs
1257A - Two Rival Students
1415A - Prison Break
1271A - Suits
259B - Little Elephant and Magic Square
1389A - LCM Problem
778A - String Game
1382A - Common Subsequence
1512D - Corrupted Array
667B - Coat of Anticubism
284B - Cows and Poker Game
1666D - Deletive Editing
1433D - Districts Connection