Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector <int> temp, arr, cnt;
- int cnt1, cur, res, n;
- unordered_map <int, int> newVal;
- int main()
- {
- cin >> n;
- temp.resize(n);
- arr.resize(n);
- for (int i = 0; i < n; i ++) {
- cin >> arr[i];
- temp[i] = arr[i];
- }
- cnt.resize(n+1);
- sort(temp.begin(), temp.end());
- for (int i = 0; i < n; i ++) {
- if (i != 0 && temp[i-1] != temp[i]) cur ++;
- newVal[temp[i]] = i;
- }
- for (int i = 0; i < n; i ++) {
- arr[i] = newVal[arr[i]];
- }
- for (int i = 0; i < n; i ++) {
- if (i > 0) {
- for (int j = n-1; j >= i-1; j -= 1) {
- cnt[arr[j]] --;
- if (cnt[arr[j]] == 0) cnt1 --;
- else if (cnt[arr[j]] == 1) cnt1 ++;
- }
- }
- for (int j = i; j < n; j ++) {
- cnt[arr[j]] ++;
- if (cnt[arr[j]] == 1) cnt1 ++;
- else if (cnt[arr[j]] == 2) cnt1 --;
- if (cnt1 == 0) res ++;
- }
- }
- cout << res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement