Josif_tepe

Untitled

Feb 22nd, 2026
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <map>
  4. using namespace std;
  5. typedef long long ll;
  6. const ll MOD = 1e9 + 7;
  7. int main () {
  8.     ios_base::sync_with_stdio(false);
  9.     int n;
  10.     cin >> n;
  11.    
  12.     vector<int> v(n);
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> v[i];
  15.     }
  16.    
  17.     ll res = 0;
  18.    
  19.     for(int i = 0; i < n; i++) {
  20.         map<int, int> cnt;
  21.         int min_element = v[i];
  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.                 res %= MOD;
  30.             }
  31.         }
  32.     }
  33.    
  34.     cout << res << endl;
  35.    
  36.    
  37.     return 0;
  38. }
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment