#include <bits/stdc++.h>
#define DIM 100010
#define MOD 1000000007
using namespace std;
int h[DIM],w[DIM];
deque<pair <int,int> > d;
int n,i;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n;
for (i=1;i<=n;i++)
cin>>h[i];
for (i=1;i<=n;i++)
cin>>w[i];
n++; /// mai adaug un dreptunghi fictiv
d.push_back(make_pair(0,0));
int sol = 0;
for (i=1;i<=n;i++){
int latime = 0;
while (!d.empty() && h[i] < d.back().first){
/// trb sa adun partea de sus care ar ramane cand scot asta din stiva
int h_ant = max (h[i],d[d.size()-2].first);
int dif = d.back().first - h_ant; /// inalimea partii de sus
latime = (latime + d.back().second) % MOD;
/// mai trb sa numar si dreptunghiurile care au inceputu in partea aia de sus si se continua in jos
sol += ( 1LL * dif * (dif + 1) / 2 + 1LL * dif * h_ant % MOD) % MOD * (1LL * latime * (latime+1) / 2) % MOD;
sol %= MOD;
d.pop_back();
}
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] + latime) % MOD));
}
cout<<sol;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |