이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |