#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,ans = 0;
cin >> n;
vector<long long> haha(n+1);
vector<long long> bruh(n+1);
for(long long i = 1; i <= n; i++) {
cin >> haha[i];
}
for(long long i = 1; i <= n; i++) {
cin >> bruh[i];
bruh[i]+=bruh[i-1];
}
vector<pair<long long,long long>> wut(0);
for(long long i = 1; i <= n; i++) {
wut.push_back({haha[i],i});
}
sort(wut.begin(),wut.end());
set<long long> idk;
idk.insert(0);
idk.insert(n+1);
for(long long i = 0; i < n; i++) {
long long p = wut[i].second,h = wut[i].first;
long long r = *idk.lower_bound(p);
long long l = *(--idk.upper_bound(p));
idk.insert(p);
long long x = (bruh[r-1]-bruh[l])%MOD,y = (bruh[r-1]-bruh[p])%MOD,z = (bruh[p-1]-bruh[l])%MOD;
cout << x << " " << y << " " << z << endl;
ans+=((x*(x+1)/2-y*(y+1)/2-z*(z+1)/2)%MOD)*((h*(h+1)/2)%MOD);
ans%=MOD;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |