This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DIM 100010
#define MOD 1000000007
using namespace std;
long long h[DIM],w[DIM];
deque<pair <long long,long long> > d;
int n,i;
int main (){
cin>>n;
for (i=1;i<=n;i++)
cin>>h[i];
for (i=1;i<=n;i++)
cin>>w[i];
n++;
d.push_back(make_pair(0,0));
long long sol = 0;
for (i=1;i<=n;i++){
long long latime = 0;
while (!d.empty() && h[i] < d.back().first){
long long h_ant = max (h[i],d[d.size()-2].first);
long long dif = (d.back().first - h_ant + MOD) % MOD;
latime = (latime + d.back().second) % MOD;
sol += ( dif * (dif + 1) / 2 % MOD + dif * h_ant % MOD) % MOD * (1LL * latime * (latime+1) / 2 % MOD) % MOD;
sol %= MOD;
d.pop_back();
}
w[i] = (w[i] + latime) % MOD;
if (h[i] == d.back().first)
d.back().second = (d.back().second + w[i]) % MOD;
else d.push_back(make_pair(h[i],w[i]));
}
cout<<(sol+MOD)%MOD;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |