#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
#include <unordered_map>
#define endl '\n'
#define mid ((l+r)/2)
#define F first
#define S second
#define pb push_back
#define yes void (cout<<"YES"<<endl)
#define no void (cout<<"NO"<<endl)
#define ump unordered_map <ll,ll>
#define sp " "
#define vll vector<ll>
#define vint vector<int>
#define pll pair<ll,ll>
typedef long long ll;
using namespace std;
const ll inf=1e18+9;
const ll M=1e9+7;
ll n;
ll h[100009];
ll w[100009];
int main(){
cin>>n;
for(ll i=0 ; i<n ; i++){
cin>>h[i];
}
ll W=0;
for(ll i=0 ; i<n ; i++){
cin>>w[i];
W+=w[i];
W%=M;
}
ll ans=((W*(W+1))/2)%M;
vector<pll> v;
v.pb({h[0],w[0]});
for(ll i=1 ; i<n ; i++){
if(h[i]==h[i-1]){
v[v.size()-1].S+=w[i];
v[v.size()-1].S%=M;
}
else
v.pb({h[i],w[i]});
}
for(auto it : v){
//cout<<it.F<<sp<<it.S<<endl;
if(it.F==1)continue;
ll x=((it.S*(it.S+1))/2)%M;
x=(x*2)%M;
ans=(ans+x)%M;
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
20 ms |
1752 KB |
Output is correct |
4 |
Correct |
40 ms |
2548 KB |
Output is correct |
5 |
Correct |
39 ms |
3024 KB |
Output is correct |
6 |
Correct |
39 ms |
2508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |