#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;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
20 ms |
4808 KB |
Output is correct |
4 |
Correct |
46 ms |
9420 KB |
Output is correct |
5 |
Correct |
41 ms |
9252 KB |
Output is correct |
6 |
Correct |
39 ms |
9416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
1240 KB |
Output is correct |
3 |
Correct |
25 ms |
5300 KB |
Output is correct |
4 |
Correct |
47 ms |
10188 KB |
Output is correct |
5 |
Correct |
48 ms |
10188 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
1240 KB |
Output is correct |
4 |
Correct |
22 ms |
5192 KB |
Output is correct |
5 |
Correct |
47 ms |
10188 KB |
Output is correct |
6 |
Correct |
53 ms |
10192 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
1236 KB |
Output is correct |
9 |
Incorrect |
22 ms |
5332 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
500 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
564 KB |
Output is correct |
15 |
Correct |
1 ms |
532 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
20 ms |
4752 KB |
Output is correct |
12 |
Correct |
44 ms |
9416 KB |
Output is correct |
13 |
Correct |
41 ms |
9416 KB |
Output is correct |
14 |
Correct |
38 ms |
9244 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1444 KB |
Output is correct |
17 |
Correct |
32 ms |
5164 KB |
Output is correct |
18 |
Correct |
62 ms |
10076 KB |
Output is correct |
19 |
Correct |
50 ms |
10184 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
1444 KB |
Output is correct |
22 |
Incorrect |
22 ms |
5292 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |