Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-05-28-16.51.29
- ***/
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define get_lost_idiot return 0
- #define nl '\n'
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- ll n,m=0,i,j,k,l=0;
- cin>>n;
- ll a[n+4];
- for(i=0;i<n;i++)
- {
- cin>>a[i];
- m+=(i+1)*(n-i)*a[i];
- }
- for(i=0;i<n;i++)
- {
- ll lo=i-1,hi=i+1;
- while(lo>=0 && a[lo]>=a[i]) lo--;
- while(hi<n && a[hi]>a[i]) hi++;
- l+=((i-lo)*(hi-i)*(hi-lo)/2)*a[i];
- }
- cout<<"Case "<<cs<<": "<<m-l<<nl;
- }
- get_lost_idiot;
- }
Advertisement
Add Comment
Please, Sign In to add comment