#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=1e6+10;
ll h[N], w[N], sm[N][N], mn[N][N];
int n;
ll eq(ll x)
{
return (x+1)*x/2%MOD;
}
int main()
{
setIO();
cin >> n;
FOR(i, 0, n) cin >> h[i];
FOR(i, 0, n) cin >> w[i];
FOR(i, 0, n)
{
sm[i][i]=w[i];
mn[i][i]=h[i];
FOR(j, i+1, n)
{
mn[i][j]=min(mn[i][j-1], h[j]);
sm[i][j]+=w[j];
sm[i][j]%=MOD;
}
}
ll ans=0;
FOR(i, 0, n)
{
ans+=eq(h[i])*eq(w[i])%MOD;
ans%=MOD;
FOR(j, i+1, n)
{
ans+=eq(sm[i][j])*eq(mn[i][j])%MOD;
ans-=eq(sm[i][j]-w[i])*eq(mn[i][j])%MOD;
ans-=eq(sm[i][j]-w[j])*eq(mn[i][j])%MOD;
ans+=eq(sm[i][j]-w[i]-w[j])*eq(mn[i][j])%MOD;
ans%=MOD;
}
}
cout << ans;
}
Compilation message
fancyfence.cpp: In function 'void setIO(std::string)':
fancyfence.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/ccupooPo.o: in function `setIO()':
fancyfence.cpp:(.text+0x12): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
fancyfence.cpp:(.text+0x1d): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
/tmp/ccupooPo.o: in function `setIO(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
fancyfence.cpp:(.text+0x69): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
fancyfence.cpp:(.text+0x80): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
/tmp/ccupooPo.o: in function `main':
fancyfence.cpp:(.text.startup+0xf): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
fancyfence.cpp:(.text.startup+0x1c): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccupooPo.o
fancyfence.cpp:(.text.startup+0x36): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
fancyfence.cpp:(.text.startup+0x3d): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
fancyfence.cpp:(.text.startup+0x48): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
fancyfence.cpp:(.text.startup+0x8f): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccupooPo.o
fancyfence.cpp:(.text.startup+0x99): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status