Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <map>
- using namespace std;
- typedef long long ll;
- const ll MOD = 1e9 + 7;
- int main () {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- ll res = 0;
- for(int i = 0; i < n; i++) {
- map<int, int> cnt;
- int min_element = v[i];
- for(int j = i; j < n; j++) {
- min_element = min(min_element, v[j]);
- cnt[v[j]]++;
- if(cnt[min_element] >= 2) {
- res++;
- res %= MOD;
- }
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment