Iamtui1010

fcb030_unique

Nov 9th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<fstream>
  4. #include<vector>
  5. #include<algorithm>
  6.  
  7. #define long long long
  8. #define nln '\n'
  9.  
  10. const long N = 2*1e5+10;
  11.  
  12. using namespace std;
  13.  
  14. // Global variables: f1, f2, n, a
  15.  
  16. fstream f1, f2;
  17.  
  18. inline void openf()
  19. {
  20.     f1.open("unique.inp", ios:: in);
  21.     f2.open("unique.out", ios:: out);
  22. }
  23.  
  24. inline void closef()
  25. {
  26.     f1.close();
  27.     f2.close();
  28. }
  29.  
  30. long n;
  31. vector<pair<long, long>> a;
  32.  
  33. void data()
  34. {
  35.     f1.tie(0)->sync_with_stdio(0);
  36.     f2.tie(0)->sync_with_stdio(0);
  37.     cin.tie(0)->sync_with_stdio(0);
  38.     cin >> n;
  39.     for (long i = 0; i != n; ++i)
  40.     {
  41.         long x;
  42.         cin >> x;
  43.         a.push_back({x, i+1});
  44.     }
  45. }
  46.  
  47. long ans = -1;
  48.  
  49. void process()
  50. {
  51.     sort(a.begin(), a.end());
  52.  
  53.     //for (const auto &i : a)
  54.     //  cout << i.second << " - " << i.first << nln;
  55.  
  56.     if (n == 1)
  57.     {
  58.         ans = 1;
  59.         return;
  60.     }
  61.  
  62.     if (a[0].first != a[1].first)
  63.     {
  64.         ans = a[0].second;
  65.         return;
  66.     }
  67.  
  68.     for (long i = 1; i != n-1; ++i)
  69.     {
  70.         if (a[i].first != a[i-1].first && a[i].first != a[i+1].first)
  71.         {
  72.             ans = a[i].second;
  73.             return;
  74.         }
  75.     }
  76.  
  77.     if (a[n-1].first != a[n-2].first)
  78.     {
  79.         ans = a[n-1].second;
  80.         return;
  81.     }
  82. }
  83.  
  84. void view()
  85. {
  86.     cout << ans << nln;
  87. }
  88.  
  89. int main()
  90. {
  91.     openf();
  92.     data();
  93.     process();
  94.     view();
  95.     closef();
  96.     return 0;
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment