#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 5000000000000000000LL
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
ll mod=1000000007LL;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll N; cin>>N; vector<ll> h,w; In(h,N); In(w,N);
vector<ll> NSL, NSR;
REP(i,0,N) {NSL.pb(-1LL); NSR.pb(N);}
vector<ll> chain;
REP(i,0,N)
{
while(chain.size()>0 && h[i]<h[chain[chain.size()-1]]) {chain.pop_back();}
chain.pb(i);
if(chain.size()>1) {NSL[i]=chain[chain.size()-2];}
}
chain.clear();
for(ll i=N-1;i>=0;i--)
{
while(chain.size()>0 && h[i]<=h[chain[chain.size()-1]]) {chain.pop_back();}
chain.pb(i);
if(chain.size()>1) {NSR[i]=chain[chain.size()-2];}
}
vector<ll> ps; ll sum=0LL; ps.pb(sum); REP(i,0,N) {sum+=w[i]; sum%=mod; ps.pb(sum);}
ll t_ans=0LL;
REP(s,0,N)
{
ll L = NSL[s]+1LL;
ll R = NSR[s]-1LL;
ll W1 = ps[s]-ps[L]; W1%=mod; ll W2 = ps[R+1]-ps[s+1]; W2%=mod;
ll ans = ((W1*W2)%mod) + ((W1*w[s])%mod) + ((W2*w[s])%mod) + (((w[s]*(w[s]+1LL))/2LL)%mod);
ans%=mod; ans*=(((h[s]*(h[s]+1LL))/2LL)%mod);
ans%=mod;
t_ans+=ans;
t_ans%=mod;
}
if(t_ans<0) {t_ans+=mod;}
cout<<t_ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
3068 KB |
Output is correct |
4 |
Correct |
32 ms |
6600 KB |
Output is correct |
5 |
Correct |
33 ms |
6432 KB |
Output is correct |
6 |
Correct |
32 ms |
6168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
1024 KB |
Output is correct |
3 |
Correct |
19 ms |
3196 KB |
Output is correct |
4 |
Correct |
39 ms |
6424 KB |
Output is correct |
5 |
Correct |
41 ms |
6420 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
1024 KB |
Output is correct |
4 |
Correct |
20 ms |
3228 KB |
Output is correct |
5 |
Correct |
39 ms |
6680 KB |
Output is correct |
6 |
Correct |
41 ms |
6820 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
1152 KB |
Output is correct |
9 |
Correct |
20 ms |
4240 KB |
Output is correct |
10 |
Correct |
37 ms |
7576 KB |
Output is correct |
11 |
Correct |
37 ms |
7704 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
16 ms |
3068 KB |
Output is correct |
12 |
Correct |
32 ms |
6812 KB |
Output is correct |
13 |
Correct |
33 ms |
6804 KB |
Output is correct |
14 |
Correct |
32 ms |
6552 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
19 ms |
4212 KB |
Output is correct |
18 |
Correct |
39 ms |
7712 KB |
Output is correct |
19 |
Correct |
41 ms |
7904 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
1152 KB |
Output is correct |
22 |
Correct |
20 ms |
4220 KB |
Output is correct |
23 |
Correct |
38 ms |
7576 KB |
Output is correct |
24 |
Correct |
38 ms |
7700 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
1152 KB |
Output is correct |
31 |
Correct |
5 ms |
1152 KB |
Output is correct |
32 |
Correct |
19 ms |
3708 KB |
Output is correct |
33 |
Correct |
20 ms |
3708 KB |
Output is correct |
34 |
Correct |
39 ms |
6816 KB |
Output is correct |
35 |
Correct |
39 ms |
6808 KB |
Output is correct |
36 |
Correct |
40 ms |
6936 KB |
Output is correct |
37 |
Correct |
40 ms |
6936 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
39 ms |
6936 KB |
Output is correct |
40 |
Correct |
38 ms |
6944 KB |
Output is correct |
41 |
Correct |
37 ms |
7316 KB |
Output is correct |
42 |
Correct |
38 ms |
7576 KB |
Output is correct |