Josif_tepe

Untitled

Feb 25th, 2026
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. //#include <bits/stdc++.h>
  5. using namespace std;
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     int n;
  10.     cin >> n;
  11.    
  12.     vector<int> v(n);
  13.    
  14.     for(int i = 0; i < n; i++) {
  15.         cin >> v[i];
  16.     }
  17.    
  18.     int res = 0;
  19.     for(int i = 0; i < n; i++) {
  20.         int min_element = v[i];
  21.         map<int, int> cnt;
  22.        
  23.         for(int j = i; j < n; j++) {
  24.             min_element = min(min_element, v[j]);
  25.             cnt[v[j]]++;
  26.            
  27.             if(cnt[min_element] >= 2) {
  28.                 res++;
  29.             }
  30.         }
  31.     }
  32.    
  33.     cout << res << endl;
  34.  
  35.    
  36.    
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment