Josif_tepe

Untitled

Feb 23rd, 2026
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4.  
  5. const int MOD = 1e9 + 7;
  6. using namespace std;
  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.     int res = 0;
  18.    
  19.     for(int i = 0; i < n; i++) {
  20.         int min_element = v[i];
  21.         map<int, int> cnt;
  22.         for(int j = i; j < n; j++) {
  23.             min_element = min(min_element, v[j]);
  24.            
  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.     return 0;
  36. }
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment