QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506883 | #8712. Flooding Wall | Qwerty1232# | 12 | 485ms | 37640kb | C++23 | 3.1kb | 2024-08-06 00:58:33 | 2024-08-06 00:58:33 |
Judging History
answer
#include <bits/stdc++.h>
constexpr int mod = 1e9 + 7;
int add(int a, int b) {
return a + b - mod * (a + b >= mod);
}
int add(int a, auto... args) {
return add(a, add(args...));
}
void add_to(int& a, int b) {
a = add(a, b);
}
int mul(int a, int b) {
return a * 1ULL * b % mod;
}
int mul(int a, auto... args) {
return mul(a, mul(args...));
}
int power(int b, int e) {
int r = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
r = mul(r, b);
b = mul(b, b);
}
return r;
}
struct ST {
struct Data {
int len;
int cnt0, cnt1;
int fuck, fuck_l, fuck_r;
Data(int val = -1) {
if (val == -1) {
len = 0;
return;
}
len = 1;
cnt0 = 2 - val;
cnt1 = val;
fuck = 0;
fuck_l = 0;
fuck_r = 0;
}
};
Data merge(Data a, Data b) {
if (a.len == 0 || b.len == 0) {
return a.len == 0 ? b : a;
}
Data d(-1);
d.len = a.len + b.len;
d.cnt0 = mul(a.cnt0, b.cnt0);
d.cnt1 = add(mul(a.cnt1, b.cnt1), mul(a.cnt0, b.cnt1), mul(a.cnt1, b.cnt0));
d.fuck = add(
mul(a.fuck, add(b.cnt0, b.cnt1)),
mul(b.fuck, add(a.cnt0, a.cnt1)),
mul(a.cnt1, b.fuck_l),
mul(b.cnt1, a.fuck_r));
d.fuck_l = add(mul(a.cnt0, a.len, b.cnt1), mul(a.cnt0, b.fuck_l), mul(a.fuck_l, add(b.cnt0, b.cnt1)));
d.fuck_r = add(mul(b.cnt0, b.len, a.cnt1), mul(b.cnt0, a.fuck_r), mul(b.fuck_r, add(a.cnt0, a.cnt1)));
return d;
}
std::vector<Data> data;
int size;
ST(int n) {
size = std::bit_ceil((size_t)n);
data.assign(size * 2, Data(-1));
for (int i = 0; i < n; i++) {
data[size + i] = Data(0);
}
// size = 1 << std::__lg(std::max)
}
void update(int i, int val) {
i += size;
data[i] = Data(val);
for (i >>= 1; i > 0; i >>= 1) {
data[i] = merge(data[2 * i], data[2 * i + 1]);
}
}
int get() {
return data[1].fuck;
}
};
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<std::array<int, 2>> input(n);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
std::cin >> input[j][i];
}
}
std::vector<int> vec(2 * n);
std::iota(vec.begin(), vec.end(), 0);
std::sort(vec.rbegin(), vec.rend(), [&](int a, int b) {
return input[a / 2][a % 2] < input[b / 2][b % 2];
});
ST st(n);
std::vector<int> cnt(n);
int ans = 0;
for (int i = 1; i < vec.size(); i++) {
int a = vec[i - 1], b = vec[i];
st.update(a / 2, ++cnt[a / 2]);
int dt = input[a / 2][a % 2] - input[b / 2][b % 2];
int ct = st.get();
ans = add(ans, mul(dt, ct));
}
std::cout << ans << "\n";
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 0ms
memory: 3536kb
input:
4 1 1 1 1 2 2 2 2
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3752kb
input:
10 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
output:
8268
result:
wrong answer 1st lines differ - expected: '21116', found: '8268'
Subtask #2:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 0ms
memory: 3824kb
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:
148974228
result:
wrong answer 1st lines differ - expected: '164439470', found: '148974228'
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: 470ms
memory: 37400kb
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: 12
Accepted
time: 485ms
memory: 37392kb
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: 12
Accepted
time: 480ms
memory: 37640kb
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: 12
Accepted
time: 482ms
memory: 37592kb
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%