Josif_tepe

Untitled

Feb 21st, 2026
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.    
  10.     vector<int> v(n);
  11.    
  12.     map<int, vector<int>> mapa;
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> v[i];
  15.         mapa[v[i]].push_back(i);
  16.     }
  17.    
  18.     vector<int> res(n, 0);
  19.     for(pair<int, vector<int>> p: mapa) {
  20.         int k = p.first;
  21.         vector<int> tmp = p.second;
  22.        
  23.         int sz = (int) tmp.size();
  24.        
  25.         if(sz >= 2) {
  26.             for(int i = 0; i < sz; i++) {
  27.                 int pi = tmp[i];
  28.                 int antipodalna_tocka = (pi + n/2) % n;
  29.                 // map<int, vector<int>>::iterator it = ...
  30.                 auto it = lower_bound(tmp.begin(), tmp.end(), antipodalna_tocka);
  31.                
  32.                 vector<int> kandidati;
  33.                 if(it != tmp.end()) {
  34.                     kandidati.push_back(*it);
  35.                 }
  36.                
  37.                 if(it != tmp.begin()) {
  38.                     it--;
  39.                     kandidati.push_back(*it);
  40.                 }
  41.                 kandidati.push_back(tmp[0]);
  42.                 kandidati.push_back(tmp[sz - 1]);
  43.                
  44.                 int max_elem = 0;
  45.                 for(int kan: kandidati) {
  46.                     if(kan != pi) {
  47.                         int d = abs(kan - pi);
  48.                         d = min(d, n - d);
  49.                        
  50.                         max_elem = max(max_elem, d);
  51.                     }
  52.                 }
  53.                 res[pi] = max_elem;
  54.             }
  55.         }
  56.        
  57.     }
  58.    
  59.    
  60.     for(int i = 0; i < n; i++) {
  61.         cout << res[i] << " ";
  62.     }
  63.  
  64.     return 0;
  65.    
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment