#include <stdio.h>
#define N 500000
#define N_ (1 << 19) /* N_ = pow2(ceil(log2(N))) */
#define MD 1000000007
unsigned int Z = 12345;
int rand_() {
return (Z *= 3) >> 1;
}
int pp2[N + 1];
void init() {
int i;
pp2[0] = 1;
for (i = 1; i <= N; i++)
pp2[i] = pp2[i - 1] * 2 % MD;
}
int yy[N * 2];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k)
if (yy[ii[j]] == yy[i_])
j++;
else if (yy[ii[j]] < yy[i_]) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
sort(ii, l, i);
l = k;
}
}
int sz[N_ * 2], prod[N_ * 2], pref[N_ * 2], suff[N_ * 2], n_;
void pul(int i) {
int l = i << 1, r = l | 1;
prod[i] = (long long) prod[l] * prod[r] % MD;
pref[i] = ((long long) pref[l] * pp2[sz[r]] + (long long) prod[l] * pref[r]) % MD;
suff[i] = ((long long) suff[l] * prod[r] + (long long) pp2[sz[l]] * suff[r]) % MD;
}
void build(int n) {
int i;
n_ = 1;
while (n_ < n)
n_ <<= 1;
for (i = 0; i < n_; i++)
if (i < n)
sz[n_ + i] = 1;
else
prod[n_ + i] = 1;
for (i = n_ - 1; i > 0; i--)
sz[i] = sz[i << 1 | 0] + sz[i << 1 | 1], pul(i);
}
void update(int i) {
i += n_;
pref[i] = suff[i] = ++prod[i];
while (i > 1)
pul(i >>= 1);
}
int main() {
static int ii[N * 2];
int n, h, i, x, sum, ans;
init();
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &yy[i << 1 | 0]);
for (i = 0; i < n; i++)
scanf("%d", &yy[i << 1 | 1]);
for (i = 0; i < n * 2; i++)
ii[i] = i;
sort(ii, 0, n * 2);
build(n);
ans = 0;
for (h = 0; h < n * 2; h++) {
x = ((long long) pp2[n] * n - pref[1] - suff[1] + (long long) prod[1] * n + MD * 2) % MD;
ans = (ans + (long long) x * (yy[ii[h]] - (h == 0 ? 0 : yy[ii[h - 1]]))) % MD;
update(ii[h] >> 1);
}
sum = 0;
for (i = 0; i < n * 2; i++)
sum = (sum + yy[i]) % MD;
ans = (ans - (long long) sum * pp2[n - 1] % MD + MD) % MD;
printf("%d\n", ans);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:81:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:83:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | scanf("%d", &yy[i << 1 | 0]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:85:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | scanf("%d", &yy[i << 1 | 1]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2392 KB |
Output is correct |
12 |
Correct |
3 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
4 ms |
2396 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2396 KB |
Output is correct |
20 |
Correct |
3 ms |
2392 KB |
Output is correct |
21 |
Correct |
3 ms |
2396 KB |
Output is correct |
22 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2400 KB |
Output is correct |
5 |
Correct |
3 ms |
2408 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2392 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
2 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
3 ms |
2396 KB |
Output is correct |
21 |
Correct |
3 ms |
2396 KB |
Output is correct |
22 |
Correct |
3 ms |
2432 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
3 ms |
2648 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2400 KB |
Output is correct |
5 |
Correct |
3 ms |
2408 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2392 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
2 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
3 ms |
2396 KB |
Output is correct |
21 |
Correct |
3 ms |
2396 KB |
Output is correct |
22 |
Correct |
3 ms |
2432 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
3 ms |
2648 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2396 KB |
Output is correct |
27 |
Correct |
9 ms |
2904 KB |
Output is correct |
28 |
Correct |
8 ms |
2912 KB |
Output is correct |
29 |
Correct |
7 ms |
2824 KB |
Output is correct |
30 |
Correct |
7 ms |
3012 KB |
Output is correct |
31 |
Correct |
8 ms |
2908 KB |
Output is correct |
32 |
Correct |
7 ms |
2988 KB |
Output is correct |
33 |
Correct |
7 ms |
2908 KB |
Output is correct |
34 |
Correct |
9 ms |
2908 KB |
Output is correct |
35 |
Correct |
7 ms |
2920 KB |
Output is correct |
36 |
Correct |
7 ms |
2908 KB |
Output is correct |
37 |
Correct |
6 ms |
3020 KB |
Output is correct |
38 |
Correct |
7 ms |
2808 KB |
Output is correct |
39 |
Correct |
8 ms |
2968 KB |
Output is correct |
40 |
Correct |
8 ms |
2976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2392 KB |
Output is correct |
12 |
Correct |
3 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
4 ms |
2396 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2396 KB |
Output is correct |
20 |
Correct |
3 ms |
2392 KB |
Output is correct |
21 |
Correct |
3 ms |
2396 KB |
Output is correct |
22 |
Correct |
3 ms |
2396 KB |
Output is correct |
23 |
Correct |
4 ms |
2392 KB |
Output is correct |
24 |
Correct |
3 ms |
2396 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2400 KB |
Output is correct |
27 |
Correct |
3 ms |
2408 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
3 ms |
2392 KB |
Output is correct |
31 |
Correct |
3 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
3 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
2 ms |
2396 KB |
Output is correct |
38 |
Correct |
3 ms |
2396 KB |
Output is correct |
39 |
Correct |
2 ms |
2396 KB |
Output is correct |
40 |
Correct |
2 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
3 ms |
2396 KB |
Output is correct |
43 |
Correct |
3 ms |
2396 KB |
Output is correct |
44 |
Correct |
3 ms |
2432 KB |
Output is correct |
45 |
Correct |
3 ms |
2396 KB |
Output is correct |
46 |
Correct |
3 ms |
2648 KB |
Output is correct |
47 |
Correct |
3 ms |
2396 KB |
Output is correct |
48 |
Correct |
3 ms |
2396 KB |
Output is correct |
49 |
Correct |
9 ms |
2904 KB |
Output is correct |
50 |
Correct |
8 ms |
2912 KB |
Output is correct |
51 |
Correct |
7 ms |
2824 KB |
Output is correct |
52 |
Correct |
7 ms |
3012 KB |
Output is correct |
53 |
Correct |
8 ms |
2908 KB |
Output is correct |
54 |
Correct |
7 ms |
2988 KB |
Output is correct |
55 |
Correct |
7 ms |
2908 KB |
Output is correct |
56 |
Correct |
9 ms |
2908 KB |
Output is correct |
57 |
Correct |
7 ms |
2920 KB |
Output is correct |
58 |
Correct |
7 ms |
2908 KB |
Output is correct |
59 |
Correct |
6 ms |
3020 KB |
Output is correct |
60 |
Correct |
7 ms |
2808 KB |
Output is correct |
61 |
Correct |
8 ms |
2968 KB |
Output is correct |
62 |
Correct |
8 ms |
2976 KB |
Output is correct |
63 |
Correct |
10 ms |
3164 KB |
Output is correct |
64 |
Correct |
9 ms |
3160 KB |
Output is correct |
65 |
Correct |
8 ms |
3184 KB |
Output is correct |
66 |
Correct |
8 ms |
2908 KB |
Output is correct |
67 |
Correct |
8 ms |
3008 KB |
Output is correct |
68 |
Correct |
8 ms |
2880 KB |
Output is correct |
69 |
Correct |
8 ms |
2904 KB |
Output is correct |
70 |
Correct |
9 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
7 ms |
3016 KB |
Output is correct |
11 |
Correct |
7 ms |
2908 KB |
Output is correct |
12 |
Correct |
7 ms |
3044 KB |
Output is correct |
13 |
Correct |
10 ms |
2948 KB |
Output is correct |
14 |
Correct |
353 ms |
28160 KB |
Output is correct |
15 |
Correct |
278 ms |
28240 KB |
Output is correct |
16 |
Correct |
285 ms |
28244 KB |
Output is correct |
17 |
Correct |
275 ms |
28240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2392 KB |
Output is correct |
12 |
Correct |
3 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
4 ms |
2396 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
2 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2396 KB |
Output is correct |
20 |
Correct |
3 ms |
2392 KB |
Output is correct |
21 |
Correct |
3 ms |
2396 KB |
Output is correct |
22 |
Correct |
3 ms |
2396 KB |
Output is correct |
23 |
Correct |
4 ms |
2392 KB |
Output is correct |
24 |
Correct |
3 ms |
2396 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2400 KB |
Output is correct |
27 |
Correct |
3 ms |
2408 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
3 ms |
2392 KB |
Output is correct |
31 |
Correct |
3 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
3 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
2 ms |
2396 KB |
Output is correct |
38 |
Correct |
3 ms |
2396 KB |
Output is correct |
39 |
Correct |
2 ms |
2396 KB |
Output is correct |
40 |
Correct |
2 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
3 ms |
2396 KB |
Output is correct |
43 |
Correct |
3 ms |
2396 KB |
Output is correct |
44 |
Correct |
3 ms |
2432 KB |
Output is correct |
45 |
Correct |
3 ms |
2396 KB |
Output is correct |
46 |
Correct |
3 ms |
2648 KB |
Output is correct |
47 |
Correct |
3 ms |
2396 KB |
Output is correct |
48 |
Correct |
3 ms |
2396 KB |
Output is correct |
49 |
Correct |
9 ms |
2904 KB |
Output is correct |
50 |
Correct |
8 ms |
2912 KB |
Output is correct |
51 |
Correct |
7 ms |
2824 KB |
Output is correct |
52 |
Correct |
7 ms |
3012 KB |
Output is correct |
53 |
Correct |
8 ms |
2908 KB |
Output is correct |
54 |
Correct |
7 ms |
2988 KB |
Output is correct |
55 |
Correct |
7 ms |
2908 KB |
Output is correct |
56 |
Correct |
9 ms |
2908 KB |
Output is correct |
57 |
Correct |
7 ms |
2920 KB |
Output is correct |
58 |
Correct |
7 ms |
2908 KB |
Output is correct |
59 |
Correct |
6 ms |
3020 KB |
Output is correct |
60 |
Correct |
7 ms |
2808 KB |
Output is correct |
61 |
Correct |
8 ms |
2968 KB |
Output is correct |
62 |
Correct |
8 ms |
2976 KB |
Output is correct |
63 |
Correct |
10 ms |
3164 KB |
Output is correct |
64 |
Correct |
9 ms |
3160 KB |
Output is correct |
65 |
Correct |
8 ms |
3184 KB |
Output is correct |
66 |
Correct |
8 ms |
2908 KB |
Output is correct |
67 |
Correct |
8 ms |
3008 KB |
Output is correct |
68 |
Correct |
8 ms |
2880 KB |
Output is correct |
69 |
Correct |
8 ms |
2904 KB |
Output is correct |
70 |
Correct |
9 ms |
2908 KB |
Output is correct |
71 |
Correct |
2 ms |
2392 KB |
Output is correct |
72 |
Correct |
3 ms |
2396 KB |
Output is correct |
73 |
Correct |
2 ms |
2396 KB |
Output is correct |
74 |
Correct |
2 ms |
2396 KB |
Output is correct |
75 |
Correct |
3 ms |
2396 KB |
Output is correct |
76 |
Correct |
3 ms |
2396 KB |
Output is correct |
77 |
Correct |
2 ms |
2396 KB |
Output is correct |
78 |
Correct |
3 ms |
2396 KB |
Output is correct |
79 |
Correct |
3 ms |
2396 KB |
Output is correct |
80 |
Correct |
7 ms |
3016 KB |
Output is correct |
81 |
Correct |
7 ms |
2908 KB |
Output is correct |
82 |
Correct |
7 ms |
3044 KB |
Output is correct |
83 |
Correct |
10 ms |
2948 KB |
Output is correct |
84 |
Correct |
353 ms |
28160 KB |
Output is correct |
85 |
Correct |
278 ms |
28240 KB |
Output is correct |
86 |
Correct |
285 ms |
28244 KB |
Output is correct |
87 |
Correct |
275 ms |
28240 KB |
Output is correct |
88 |
Correct |
547 ms |
36084 KB |
Output is correct |
89 |
Correct |
494 ms |
35976 KB |
Output is correct |
90 |
Correct |
307 ms |
28244 KB |
Output is correct |
91 |
Correct |
323 ms |
36160 KB |
Output is correct |
92 |
Correct |
349 ms |
28284 KB |
Output is correct |
93 |
Correct |
308 ms |
28144 KB |
Output is correct |
94 |
Correct |
345 ms |
36028 KB |
Output is correct |
95 |
Correct |
308 ms |
28372 KB |
Output is correct |
96 |
Correct |
364 ms |
32180 KB |
Output is correct |
97 |
Correct |
335 ms |
31940 KB |
Output is correct |