Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<int> v(n);
- map<int, vector<int>> mapa;
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- mapa[v[i]].push_back(i);
- }
- vector<int> res(n, 0);
- for(pair<int, vector<int>> p: mapa) {
- int k = p.first;
- vector<int> tmp = p.second;
- int sz = (int) tmp.size();
- if(sz >= 2) {
- for(int i = 0; i < sz; i++) {
- int pi = tmp[i];
- int antipodalna_tocka = (pi + n/2) % n;
- // map<int, vector<int>>::iterator it = ...
- auto it = lower_bound(tmp.begin(), tmp.end(), antipodalna_tocka);
- vector<int> kandidati;
- if(it != tmp.end()) {
- kandidati.push_back(*it);
- }
- if(it != tmp.begin()) {
- it--;
- kandidati.push_back(*it);
- }
- kandidati.push_back(tmp[0]);
- kandidati.push_back(tmp[sz - 1]);
- int max_elem = 0;
- for(int kan: kandidati) {
- if(kan != pi) {
- int d = abs(kan - pi);
- d = min(d, n - d);
- max_elem = max(max_elem, d);
- }
- }
- res[pi] = max_elem;
- }
- }
- }
- for(int i = 0; i < n; i++) {
- cout << res[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment