vector<int> a[2001]; int originalData[1000010]; int thInA[1000010]; // int loc[2001]; priority_queue<int, vector<int>, greater<int>> pq;
intmain(){ int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cd(originalData[i]); thInA[i] = a[originalData[i]].size(); a[originalData[i]].push_back(i); } int ans = INT_MAX; int ansA, ansB; int maxValInQueue = 0; for (int i = 1; i <= m; i++) { pq.push(a[i][0]); maxValInQueue = max(maxValInQueue, a[i][0]); } while (true) { int minValInQueue = pq.top(); pq.pop(); if (maxValInQueue - minValInQueue < ans) { ans = maxValInQueue - minValInQueue; ansA = minValInQueue, ansB = maxValInQueue; } int removedWhose = originalData[minValInQueue]; int thOfHim = thInA[minValInQueue]; thOfHim++; if (thOfHim == a[removedWhose].size()) { break; } int newVal = a[removedWhose][thOfHim]; maxValInQueue = max(maxValInQueue, newVal); pq.push(newVal); } cout << ansA << " " << ansB << endl; return0; }