This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = (ll)1<<62;
const ll MOD = 1e9+7;
const int iINF = 1<<30;
const double PI = 3.14159265359;
ll nC2(ll n){
if(n < 0) return 0;
return (n*(n-1)/2) % MOD;
}
void solve(){
int n;
cin >> n;
vector<ll> h(n), w(n);
for(ll& x : h) cin >> x;
for(ll& x : w) cin >> x;
map<ll, ll> mp;
ll s = 0, ans = 0;
for(int i=0;i<n;i++){
auto it = mp.upper_bound(h[i]);
for(;it!=mp.end();){
s = (s - nC2(it->ff+1)*it->ss + MOD)%MOD;
s = (s + nC2(h[i]+1)*it->ss + MOD)%MOD;
mp[h[i]] = (mp[h[i]] + it->ss)%MOD;
it = mp.erase(it);
}
ans = (ans + nC2(h[i]+1)*nC2(w[i]+1)%MOD + s*w[i]%MOD)%MOD;
s = (s + nC2(h[i]+1)*w[i]%MOD)%MOD;
mp[h[i]] = (mp[h[i]] + w[i])%MOD;
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |