Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector <int> temp, arr, cnt;
  4. int cnt1, cur, res, n;
  5. unordered_map <int, int> newVal;
  6. int main()
  7. {
  8. cin >> n;
  9. temp.resize(n);
  10. arr.resize(n);
  11. for (int i = 0; i < n; i ++) {
  12. cin >> arr[i];
  13. temp[i] = arr[i];
  14. }
  15. cnt.resize(n+1);
  16. sort(temp.begin(), temp.end());
  17. for (int i = 0; i < n; i ++) {
  18. if (i != 0 && temp[i-1] != temp[i]) cur ++;
  19. newVal[temp[i]] = i;
  20. }
  21. for (int i = 0; i < n; i ++) {
  22. arr[i] = newVal[arr[i]];
  23. }
  24. for (int i = 0; i < n; i ++) {
  25. if (i > 0) {
  26. for (int j = n-1; j >= i-1; j -= 1) {
  27. cnt[arr[j]] --;
  28. if (cnt[arr[j]] == 0) cnt1 --;
  29. else if (cnt[arr[j]] == 1) cnt1 ++;
  30. }
  31. }
  32.  
  33. for (int j = i; j < n; j ++) {
  34. cnt[arr[j]] ++;
  35. if (cnt[arr[j]] == 1) cnt1 ++;
  36. else if (cnt[arr[j]] == 2) cnt1 --;
  37.  
  38. if (cnt1 == 0) res ++;
  39. }
  40. }
  41. cout << res;
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement