Submission #1364323

#TimeUsernameProblemLanguageResultExecution timeMemory
1364323shahaprogGift Boxes (EGOI25_giftboxes)C++20
19 / 100
982 ms39576 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define Shahriyor ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi> 
#define vc vector<char>
#define vs vector<string>
#define vp vector<pair<int,int>>
#define vvp vector<vector<pair<int,int>>>
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define endl '\n'
#define len(a) (int)(a).length()
#define inf 4e18
#define print(x) { cout << x << endl; return; }

void Solve();
int mod = 1e9+7;
int LOG = 20;
vi dx = {-1, 1, 0, 0, 1, -1, 1, -1};
vi dy = {0, 0, 1, -1, 1, -1, -1, 1};

ostream& operator<<(ostream& out, vi& a) {
    for(int i=0;i<sz(a);i++) out << a[i] << ' ';
    return out;
}
istream& operator>>(istream& in, vi& a) {
    for(int i=0;i<sz(a);i++) in >> a[i];
    return in;
}
int sum(vi& l) {return accumulate(all(l),(int)0);}
int binpow(int a, int b){
    int res = 1;
    while(b){
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
signed main(){
    clock_t start = clock();
    Shahriyor;
    int t = 1;
    // cin >> t;
    while(t--) Solve();
    // cerr << "Time: " << double(clock() - start) / double(CLOCKS_PER_SEC) * 1000 << " ms\n";
}
int ans=inf,a,b;
int t,n;

void res(vi& l,int is_rev){
    map<int,int> temp;
    int right=n-1;
    for(int i=n-1;~i;i--){
        if(temp.count(l[i])) {right=i; break;}
        temp[l[i]]++; 
    }
    temp.clear();
    vi last_occ(t+5,0);
    for(int i=0;i<n;i++) last_occ[l[i]]=i;
    for(int i=0;i<n;i++){
        if(temp.count(l[i])) break;
        temp[l[i]]++;
        right=max(right,last_occ[l[i]]);
        if(n-(n-right+i+1)<ans){
            ans=n-(n-right+i+1);
            if(is_rev) a=n-right-1,b=n-i;
            else a=i+1,b=right;
        }
    }
}

void Solve(){
    cin>>t>>n;
    vi l(n); cin>>l;
    res(l,0);
    reverse(all(l));
    res(l,1);
    cout << a << " " << b << endl;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...