#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long twok[500005];
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
pair<long long,long long> arr[n];
for(int i=0; i<n; i++) cin >> arr[i].first;
for(int i=0; i<n; i++) cin >> arr[i].second;
vector<pair<long long,int> > hei;
for(int i=0; i<n; i++){
if(arr[i].first>arr[i].second)swap(arr[i].first,arr[i].second);
hei.push_back({arr[i].first,i});
hei.push_back({arr[i].second,i});
}
sort(hei.begin(),hei.end(),greater<pair<long long,int> >());
long long ans=0;
int st[n],add1[n],add2[n];
memset(add1,0,sizeof(add1));
memset(add2,0,sizeof(add2));
for(int i=0; i<n; i++) st[i]=2;
for(auto [h,i]:hei){
long long mult=1;
for(int j=0; j<i; j++) mult=mult*st[j]%mod;
for(int j=i+1; j<n; j++){
if(h>arr[j].first){
ans+=mult*add1[j]%mod*(h-arr[j].first)%mod;
}
if(h>arr[j].second){
ans+=mult*add1[j]%mod*(h-arr[j].second)%mod;
}
add2[j]+=mult;
if(add2[j]>=mod) add2[j]-=mod;
mult=mult*st[j]%mod;
}
mult=1;
for(int j=i+1; j<n; j++) mult=mult*st[j]%mod;
for(int j=i-1; j>=0; j--){
if(h>arr[j].first){
ans+=mult*add2[j]%mod*(h-arr[j].first)%mod;
}
if(h>arr[j].second){
ans+=mult*add2[j]%mod*(h-arr[j].second)%mod;
}
add1[j]+=mult;
if(add1[j]>=mod) add1[j]-=mod;
mult=mult*st[j]%mod;
}
st[i]--;
}
ans%=mod;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
2069 ms |
1248 KB |
Output is correct |
28 |
Correct |
1951 ms |
1244 KB |
Output is correct |
29 |
Correct |
1745 ms |
1244 KB |
Output is correct |
30 |
Correct |
1726 ms |
1248 KB |
Output is correct |
31 |
Correct |
1899 ms |
1248 KB |
Output is correct |
32 |
Correct |
1954 ms |
1248 KB |
Output is correct |
33 |
Correct |
1963 ms |
1244 KB |
Output is correct |
34 |
Correct |
1982 ms |
1244 KB |
Output is correct |
35 |
Correct |
2021 ms |
1244 KB |
Output is correct |
36 |
Correct |
1983 ms |
1248 KB |
Output is correct |
37 |
Correct |
1775 ms |
1248 KB |
Output is correct |
38 |
Correct |
1743 ms |
1244 KB |
Output is correct |
39 |
Correct |
1899 ms |
1244 KB |
Output is correct |
40 |
Correct |
1875 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
2069 ms |
1248 KB |
Output is correct |
50 |
Correct |
1951 ms |
1244 KB |
Output is correct |
51 |
Correct |
1745 ms |
1244 KB |
Output is correct |
52 |
Correct |
1726 ms |
1248 KB |
Output is correct |
53 |
Correct |
1899 ms |
1248 KB |
Output is correct |
54 |
Correct |
1954 ms |
1248 KB |
Output is correct |
55 |
Correct |
1963 ms |
1244 KB |
Output is correct |
56 |
Correct |
1982 ms |
1244 KB |
Output is correct |
57 |
Correct |
2021 ms |
1244 KB |
Output is correct |
58 |
Correct |
1983 ms |
1248 KB |
Output is correct |
59 |
Correct |
1775 ms |
1248 KB |
Output is correct |
60 |
Correct |
1743 ms |
1244 KB |
Output is correct |
61 |
Correct |
1899 ms |
1244 KB |
Output is correct |
62 |
Correct |
1875 ms |
1244 KB |
Output is correct |
63 |
Correct |
1992 ms |
1244 KB |
Output is correct |
64 |
Correct |
2023 ms |
1244 KB |
Output is correct |
65 |
Correct |
2134 ms |
1248 KB |
Output is correct |
66 |
Correct |
2174 ms |
1248 KB |
Output is correct |
67 |
Correct |
2127 ms |
1244 KB |
Output is correct |
68 |
Correct |
2065 ms |
1248 KB |
Output is correct |
69 |
Correct |
1976 ms |
1244 KB |
Output is correct |
70 |
Correct |
1978 ms |
1248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1790 ms |
1248 KB |
Output is correct |
11 |
Correct |
1837 ms |
1248 KB |
Output is correct |
12 |
Correct |
1773 ms |
1248 KB |
Output is correct |
13 |
Correct |
1765 ms |
1244 KB |
Output is correct |
14 |
Execution timed out |
5048 ms |
29864 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
2069 ms |
1248 KB |
Output is correct |
50 |
Correct |
1951 ms |
1244 KB |
Output is correct |
51 |
Correct |
1745 ms |
1244 KB |
Output is correct |
52 |
Correct |
1726 ms |
1248 KB |
Output is correct |
53 |
Correct |
1899 ms |
1248 KB |
Output is correct |
54 |
Correct |
1954 ms |
1248 KB |
Output is correct |
55 |
Correct |
1963 ms |
1244 KB |
Output is correct |
56 |
Correct |
1982 ms |
1244 KB |
Output is correct |
57 |
Correct |
2021 ms |
1244 KB |
Output is correct |
58 |
Correct |
1983 ms |
1248 KB |
Output is correct |
59 |
Correct |
1775 ms |
1248 KB |
Output is correct |
60 |
Correct |
1743 ms |
1244 KB |
Output is correct |
61 |
Correct |
1899 ms |
1244 KB |
Output is correct |
62 |
Correct |
1875 ms |
1244 KB |
Output is correct |
63 |
Correct |
1992 ms |
1244 KB |
Output is correct |
64 |
Correct |
2023 ms |
1244 KB |
Output is correct |
65 |
Correct |
2134 ms |
1248 KB |
Output is correct |
66 |
Correct |
2174 ms |
1248 KB |
Output is correct |
67 |
Correct |
2127 ms |
1244 KB |
Output is correct |
68 |
Correct |
2065 ms |
1248 KB |
Output is correct |
69 |
Correct |
1976 ms |
1244 KB |
Output is correct |
70 |
Correct |
1978 ms |
1248 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
0 ms |
348 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
1 ms |
348 KB |
Output is correct |
80 |
Correct |
1790 ms |
1248 KB |
Output is correct |
81 |
Correct |
1837 ms |
1248 KB |
Output is correct |
82 |
Correct |
1773 ms |
1248 KB |
Output is correct |
83 |
Correct |
1765 ms |
1244 KB |
Output is correct |
84 |
Execution timed out |
5048 ms |
29864 KB |
Time limit exceeded |
85 |
Halted |
0 ms |
0 KB |
- |