#include<bits/stdc++.h>
#define vi vector<int>
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<long long int, long long int>>
#define pb push_back
#define f0r(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef long long int ll;
const int mod = 1e9 + 7;
const int mxn = 1e5 + 5;
const int lg = floor(log2(mxn));
ll w[mxn];
ll h[mxn];
ll minh[lg][mxn];
ll c2(ll x){
return x * (x+1) / 2 % mod;
}
ll ans(ll w, ll h){
return c2(w) * c2(h) % mod;
}
ll minq(int l, int r){
int sz = r - l + 1;
int curlg = floor(log2(sz));
return min(minh[curlg][l], minh[curlg][r - (int)pow(2, curlg) + 1]);
}
int main(){
int n;
cin>>n;
f0r(i,n)cin>>h[i];
f0r(i,n)cin>>w[i];
f0r(i,n)minh[0][i] = h[i];
for(int l = 1;l<=floor(log2(n));l++){
f0r(i, n - pow(l, 2) + 1){
minh[l][i] = min(minh[l-1][i], minh[l-1][i + (int)pow(l-1, 2)]);
}
}
ll run = 0;
ll sumw = 0;
f0r(i,n)sumw+=w[i];
sumw %= mod;
vll twos;
f0r(i,n){
if(h[i] == 1){
if(run != 0)twos.pb(run);
run = 0;
}
else{
run += w[i];
}
}
if(run != 0)twos.pb(run);
ll ans = c2(sumw);
for(ll u : twos){
ans += 2LL * c2(u) % mod;
ans %= mod;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
2 ms |
8540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
2 ms |
8540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
2 ms |
8540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
2 ms |
8540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |