#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("input1.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n;
cin >> n;
vector<int> h(n);
map<int,int> ind; int x=1;
vector<pair<int, vector<int> > >sorted;
sorted.push_back({0, {}});
for(int i=0; i<n; i++){
cin >> h[i];
if(ind[h[i]]==0){
sorted.push_back({h[i], {}});
ind[h[i]]=x;
x++;
}
sorted[ind[h[i]]].second.push_back(i);
}
sort(sorted.begin(), sorted.end());
reverse(sorted.begin(), sorted.end());
vector<int> w(n);
for(int i=0; i<n; i++){
cin >> w[i];
}
vector<int> a(n+1);
int ans=0;
for(int i=0; i<(int)sorted.size()-1; i++){
int h=sorted[i].first;
int next=sorted[i+1].first;
vector<int> ele=sorted[i].second;
for(auto e: ele){
a[e]=w[e];
}
int s=0;
int mom=(int)0;
for(int j=0; j<=n; j++){
if(a[j]==0){
s+=((mom*(mom+1))/2)%mod;
s%=mod;
mom=0;
}
mom+=a[j];
mom%=mod;
}
int factor=((h*(h+1))/2 - (next*(next+1))/2)%mod;
ans+=(s*factor)%mod;
ans%=mod;
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
10 ms |
2148 KB |
Output is correct |
4 |
Correct |
19 ms |
4300 KB |
Output is correct |
5 |
Correct |
23 ms |
4040 KB |
Output is correct |
6 |
Correct |
16 ms |
4228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
11 ms |
2388 KB |
Output is correct |
4 |
Correct |
21 ms |
4364 KB |
Output is correct |
5 |
Correct |
27 ms |
4308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
16 ms |
2388 KB |
Output is correct |
5 |
Correct |
23 ms |
4304 KB |
Output is correct |
6 |
Correct |
23 ms |
4360 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
460 ms |
1740 KB |
Output is correct |
9 |
Execution timed out |
1086 ms |
4416 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
440 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
5 ms |
464 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
10 ms |
2700 KB |
Output is correct |
12 |
Correct |
19 ms |
5448 KB |
Output is correct |
13 |
Correct |
23 ms |
5320 KB |
Output is correct |
14 |
Correct |
18 ms |
5484 KB |
Output is correct |
15 |
Correct |
1 ms |
372 KB |
Output is correct |
16 |
Correct |
3 ms |
920 KB |
Output is correct |
17 |
Correct |
12 ms |
3348 KB |
Output is correct |
18 |
Correct |
23 ms |
6276 KB |
Output is correct |
19 |
Correct |
26 ms |
6380 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
455 ms |
1992 KB |
Output is correct |
22 |
Execution timed out |
1083 ms |
5440 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |