QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#416895 | #8712. Flooding Wall | zhoukangyang# | 12 | 69ms | 26976kb | C++14 | 3.2kb | 2024-05-22 10:32:11 | 2024-05-22 10:32:11 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int >
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
#define pb emplace_back
using namespace std;
const int N = 1 << 21, mod = 1e9 + 7;
int n;
int a[N], b[N];
int arr[N], tot;
int sum1[N], sum2[N], tag[N];
void adt(int x, int w) {
sum1[x] = (ll)sum1[x] * w % mod;
sum2[x] = (ll)sum2[x] * w % mod;
tag[x] = (ll)tag[x] * w % mod;
}
void push(int x) {
if(tag[x] != 1) adt(x * 2, tag[x]), adt(x * 2 + 1, tag[x]), tag[x] = 1;
}
void upd(int x) {
sum1[x] = (sum1[x * 2] + sum1[x * 2 + 1]) % mod;
sum2[x] = (sum2[x * 2] + sum2[x * 2 + 1]) % mod;
}
inline void add(int x, int L, int R, int l, int r, int w) {
if(l <= L && R <= r) return adt(x, w), void();
int mid = (L + R) >> 1;
push(x);
if(l <= mid) add(x * 2, L, mid, l, r, w);
if(r > mid) add(x * 2 + 1, mid + 1, R, l, r, w);
upd(x);
}
inline int query(int x, int L, int R, int l, int r) {
if(l <= L && R <= r) return sum1[x];
push(x);
int mid = (L + R) >> 1, ret = 0;
if(l <= mid) ret += query(x * 2, L, mid, l, r);
if(r > mid) ret += query(x * 2 + 1, mid + 1, R, l, r);
return ret % mod;
}
void inc(int x, int L, int R, int p, int w) {
if(L == R) return (sum1[x] += w) %= mod, (sum2[x] += (ll)w * arr[p] % mod) %= mod, void();
push(x); int mid = (L + R) >> 1; p <= mid ? inc(x * 2, L, mid, p, w) : inc(x * 2 + 1, mid + 1, R, p, w); upd(x);
}
void build(int x, int L, int R) {
tag[x] = 1;
if(L == R) return sum1[x] = sum2[x] = (L == 1), void();
int mid = (L + R) >> 1;
build(x * 2, L, mid), build(x * 2 + 1, mid + 1, R), upd(x);
}
int pw[N];
int tmp[N];
int S1() {
int ret = 0;
L(i, 1, tot) {
(ret += (ll)tmp[i] * i % mod) %= mod;
}
return ret;
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
L(i, 1, n) {
cin >> a[i];
}
L(i, 1, n) {
cin >> b[i];
}
L(i, 1, n) {
arr[++tot] = a[i];
arr[++tot] = b[i];
}
sort(arr + 1, arr + tot + 1);
tot = unique(arr + 1, arr + tot + 1) - arr - 1;
L(i, 1, n) {
a[i] = lower_bound(arr + 1, arr + tot + 1, a[i]) - arr;
b[i] = lower_bound(arr + 1, arr + tot + 1, b[i]) - arr;
assert(1 <= a[i] && a[i] <= tot);
assert(1 <= b[i] && b[i] <= tot);
}
pw[0] = 1;
L(i, 1, n) {
pw[i] = (ll)pw[i - 1] * 2 % mod;
}
L(i, 1, n) if(a[i] > b[i])swap(a[i], b[i]);
int ans = 0;
L(tst, 0, 1) {
build(1, 1, tot);
int mn = 1;
L(i, 1, tot)
tmp[i] = 0;
tmp[1] = 1;
L(i, 1, n) {
int ret = 0;
L(j, 1, a[i])
(ret += tmp[j]) %= mod, tmp[j] = 0;
tmp[a[i]] = ret;
int s = 0;
L(j, 1, b[i])
(s += tmp[j]) %= mod;
(tmp[b[i]] += s) %= mod;
L(j, b[i] + 1, tot)
tmp[j] = (ll)tmp[j] * 2 % mod;
(ans += (ll) S1() * pw[n - i] % mod) %= mod;
}
if(tst == 1) {
(ans += mod - (ll) n * S1() % mod) %= mod;
}
reverse(a + 1, a + n + 1);
reverse(b + 1, b + n + 1);
}
L(i, 1, n) {
(ans += mod - (ll) (arr[a[i]] + arr[b[i]]) * pw[n - 1] % mod) %= mod;
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 3ms
memory: 15952kb
input:
4 1 1 1 1 2 2 2 2
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 15912kb
input:
10 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
output:
21116
result:
ok single line: '21116'
Test #3:
score: 0
Accepted
time: 2ms
memory: 15908kb
input:
1 1 2
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 15908kb
input:
2 1 1 2 2
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 3ms
memory: 15968kb
input:
3 1 1 1 2 2 2
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 15956kb
input:
3 1 1 1 3 2 3
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 0ms
memory: 15904kb
input:
3 2 1 1 3 2 3
output:
4
result:
ok single line: '4'
Test #8:
score: 0
Accepted
time: 2ms
memory: 15912kb
input:
3 1 1 2 3 2 3
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 0ms
memory: 15912kb
input:
4 1 1 2 2 2 2 1 1
output:
6
result:
ok single line: '6'
Test #10:
score: -8
Wrong Answer
time: 0ms
memory: 16024kb
input:
3 1 4 4 3 1 1
output:
999999996
result:
wrong answer 1st lines differ - expected: '2', found: '999999996'
Subtask #2:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 0ms
memory: 15912kb
input:
100 948 425 211 688 416 81 356 602 712 954 117 522 797 75 281 491 662 669 78 156 939 526 929 937 916 619 166 777 48 898 449 278 298 714 668 755 679 38 389 602 195 135 672 833 655 541 473 27 596 274 351 353 598 993 837 246 950 99 179 751 481 843 550 195 964 279 806 82 330 599 124 756 649 838 513 625 ...
output:
252235778
result:
wrong answer 1st lines differ - expected: '164439470', found: '252235778'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 12
Accepted
Test #57:
score: 12
Accepted
time: 65ms
memory: 26976kb
input:
500000 1 1 1 1 2 2 2 1 1 1 1 1 2 2 1 1 2 2 2 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 2 1 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 1 2 1 2 2 1 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 1 2 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 1 2 2 2 2 2 2 1 2 2 1 1 2 1 2 1...
output:
869044223
result:
ok single line: '869044223'
Test #58:
score: 0
Accepted
time: 69ms
memory: 26568kb
input:
499993 1 1 2 1 1 2 1 1 2 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 1 1 2 2 1 2 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 2 2 1 1 2 2 2 2 2 1 1 2 1 1 2 1 1 2 2 2 1 2 2 1 2 1 1 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 1 2 1 2 1 2 2 1 2 1 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1...
output:
480826834
result:
ok single line: '480826834'
Test #59:
score: 0
Accepted
time: 65ms
memory: 26740kb
input:
500000 2 2 1 1 2 2 2 1 1 2 2 2 2 2 1 1 1 1 1 2 1 2 1 2 1 2 2 1 1 1 2 1 1 1 1 1 1 2 2 2 2 2 2 2 2 1 2 1 2 1 2 1 1 2 1 1 2 2 2 1 2 2 1 2 2 1 2 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 2 2 1 2 1 1 2 1 2 1 1 2 2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 2 2 1 1 1 1 1 1 2 2 1 1 1 2 1 2 2 2 1 1 1 2 2...
output:
869044223
result:
ok single line: '869044223'
Test #60:
score: 0
Accepted
time: 64ms
memory: 26368kb
input:
499999 2 1 2 2 1 2 1 1 2 1 1 1 2 2 2 1 1 2 2 2 1 1 1 2 2 2 2 2 1 2 2 1 1 2 2 2 2 1 1 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 1 2 1 2 1 2 1 2 2 2 1 1...
output:
192864306
result:
ok single line: '192864306'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%