| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1329658 | duo | Fancy Fence (CEOI20_fancyfence) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
// JUST ME BRO
// TRY OLP
#define ll int64_t
#define FOR(I, L, R) for(int I(L) ; I <= (int)(R) ; ++I)
#define FOD(I, R, L) for(int I(R) ; I >= (int)(L) ; --I)
#define FOA(I, A) for(auto &I : A)
#define fi first
#define se second
const ll mod = 1e9+7;
const ll N = 2e5 + 5;
ll n;
ll H[N], W[N], suf[N], sum ;
ll power(ll a, ll b){
ll res = 1;
a %= mod;
while(b){
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
void sub1 () {
ll inv2 = power(2, mod - 2);
ll x = H[1] % mod;
ll s = sum % mod;
ll a = x * ((x + 1) % mod) % mod * inv2 % mod;
ll b = s * ((s + 1) % mod) % mod * inv2 % mod;
cout << a * b % mod;
}
void sub2() {
FOD( i , N , 1 ){
suf[i] = (suf[i+1] + W[i]) % mod;
}
ll ans = 0;
ll inv2 = (mod + 1) / 2;
FOR ( i , 1 , N ){
ll ww = suf[i];
ll ways = ww % mod * ((ww + 1) % mod) % mod;
ways = ways * inv2 % mod;
ans = (ans + H[i] % mod * ways % mod) % mod;
}
cout << ans%mod; //QUEN CACH MODULO PHEP CHIA ROI SOS
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("FENCE.INP" , "r" , stdin);
// freopen("FENCE.OUT" , "w" , stdout);
cin >> n ;
bool check = false;
bool check2 = false;
FOR (i , 1 , n ) {
cin >> H[i];
if (i > 1 ) {
if ( H[i] != H[i-1]) {
check = true;
}
if ( H[i-1] > H[i])
check2 = true;
}
}
}
FOR (i , 1 , n ) {
cin >> W[i];
sum+=W[i];
}
if ( check == false ) {
sub1();
}
else if ( check2 == false ) {
sub2();
}
else {
sub2();
}
}
