Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define endl '\n'
- using namespace std;
- #ifdef ONLINE_JUDGE
- #define eprintf(...) 42
- #else
- #define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
- #endif
- clock_t startTime;
- double getCurrentTime()
- {
- return (double)(clock() - startTime) / CLOCKS_PER_SEC;
- }
- long long solve(vector<int> heights)
- {
- int n = heights.size();
- long long ans = 0;
- for(int i=0; i<n; i++)
- {
- int l = i, r = i;
- while(l>=0)
- {
- if(heights[l]>heights[i])
- {
- break;
- }
- l--;
- }
- l++;
- while(r<n)
- {
- if(heights[r]>heights[i])
- {
- break;
- }
- r++;
- }
- r--;
- ans += r - l + 1;
- }
- return ans;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(0);
- int t=1;
- //cin>>t;
- startTime = clock();
- while(t--)
- {
- startTime = clock();
- int n;
- cin>>n;
- vector<int> heights(n);
- for(int i=0; i<n; i++)
- {
- cin>>heights[i];
- }
- cout<<solve(heights)<<endl;
- }
- eprintf("time = %.5lf\n", getCurrentTime());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment