QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#484883 | #8712. Flooding Wall | fractal | 12 | 1680ms | 711828kb | C++17 | 7.1kb | 2024-07-20 04:33:08 | 2024-07-20 04:33:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 Rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 2e6 + 200;
const int M = 2e6 + 100;
const int inf = 2e9 + 3;
const ll INF = 1e18;
template<int mod>
class Modular {
public:
int val;
Modular() : val(0) {}
Modular(int new_val) : val(new_val) {}
// Modular(long long new_val) : val(new_val % mod) {} // AFFECTS OPERATOR* (because it has one more %)
friend Modular operator+(const Modular& a, const Modular& b) {
if (a.val + b.val >= mod) return a.val + b.val - mod;
else return a.val + b.val;
}
friend Modular operator-(const Modular& a, const Modular& b) {
if (a.val - b.val < 0) return a.val - b.val + mod;
else return a.val - b.val;
}
friend Modular operator*(const Modular& a, const Modular& b) {
return 1ll * a.val * b.val % mod;
}
friend Modular binpow(Modular a, long long n) {
Modular res = 1;
for (; n; n >>= 1) {
if (n & 1) res *= a;
a *= a;
}
return res;
}
/* ALTERNATIVE INVERSE FUNCTION USING EXTENDED EUCLIDEAN ALGORITHM
friend void gcd(int a, int b, Modular& x, Modular& y) {
if (a == 0) {
x = Modular(0);
y = Modular(1);
return;
}
Modular x1, y1;
gcd(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
}
friend Modular inv(const Modular& a) {
Modular x, y;
gcd(a.val, mod, x, y);
return x;
}
*/
friend Modular inv(const Modular& a) {
return binpow(a, mod - 2);
}
Modular operator/(const Modular& ot) const {
return *this * inv(ot);
}
Modular& operator++() {
if (val + 1 == mod) val = 0;
else ++val;
return *this;
}
Modular operator++(int) {
Modular tmp = *this;
++(*this);
return tmp;
}
Modular operator+() const {
return *this;
}
Modular operator-() const {
return 0 - *this;
}
Modular& operator+=(const Modular& ot) {
return *this = *this + ot;
}
Modular& operator-=(const Modular& ot) {
return *this = *this - ot;
}
Modular& operator*=(const Modular& ot) {
return *this = *this * ot;
}
Modular& operator/=(const Modular& ot) {
return *this = *this / ot;
}
bool operator==(const Modular& ot) const {
return val == ot.val;
}
bool operator!=(const Modular& ot) const {
return val != ot.val;
}
bool operator<(const Modular& ot) const {
return val < ot.val;
}
bool operator>(const Modular& ot) const {
return val > ot.val;
}
explicit operator int() const {
return val;
}
};
template<int mod>
istream& operator>>(istream& istr, Modular<mod>& x) {
return istr >> x.val;
}
template<int mod>
ostream& operator<<(ostream& ostr, const Modular<mod>& x) {
return ostr << x.val;
}
const int mod = 1e9 + 7;
using Mint = Modular<mod>;
struct node {
int l, r;
Mint sum, sumH;
Mint p;
node() {
l = r = 0;
p = 1;
sum = sumH = 0;
}
} t[N << 4];
int sz = 0;
void push(int v, int tl, int tr) {
if (t[v].p == 1) return;
if (tl != tr) {
t[v].l = (t[v].l ? t[v].l : ++sz);
t[v].r = (t[v].r ? t[v].r : ++sz);
t[t[v].l].p *= t[v].p;
t[t[v].r].p *= t[v].p;
}
t[v].sum *= t[v].p;
t[v].sumH *= t[v].p;
t[v].p = 1;
}
void upd_mul(int l, int r, Mint val, int v = 1, int tl = 0, int tr = M) {
push(v, tl, tr);
if (l <= tl && tr <= r) {
t[v].p *= val;
push(v, tl, tr);
return;
}
if (r < tl || tr < l)
return;
int tm = tl + tr >> 1;
t[v].l = (t[v].l ? t[v].l : ++sz);
t[v].r = (t[v].r ? t[v].r : ++sz);
upd_mul(l, r, val, t[v].l, tl, tm);
upd_mul(l, r, val, t[v].r, tm + 1, tr);
t[v].sum = t[t[v].l].sum + t[t[v].r].sum;
t[v].sumH = t[t[v].l].sumH + t[t[v].r].sumH;
}
void upd(int pos, Mint val, int v = 1, int tl = 0, int tr = M) {
push(v, tl, tr);
if (tr < pos || tl > pos) return;
if (tl == tr) {
t[v].sum += val;
t[v].sumH += val * Mint(tl);
return;
}
int tm = tl + tr >> 1;
t[v].l = (t[v].l ? t[v].l : ++sz);
upd(pos, val, t[v].l, tl, tm);
t[v].r = (t[v].r ? t[v].r : ++sz);
upd(pos, val, t[v].r, tm + 1, tr);
t[v].sum = t[t[v].l].sum + t[t[v].r].sum;
t[v].sumH = t[t[v].l].sumH + t[t[v].r].sumH;
}
Mint get(int l, int r, int v = 1, int tl = 0, int tr = M) {
push(v, tl, tr);
if (r < tl || tr < l || v == 0)
return 0;
if (l <= tl && tr <= r)
return t[v].sum;
int tm = tl + tr >> 1;
return get(l, r, t[v].l, tl, tm) + get(l, r, t[v].r, tm + 1, tr);
}
Mint getH(int l, int r, int v = 1, int tl = 0, int tr = M) {
push(v, tl, tr);
if (r < tl || tr < l || v == 0)
return 0;
if (l <= tl && tr <= r)
return t[v].sumH;
int tm = tl + tr >> 1;
return getH(l, r, t[v].l, tl, tm) + getH(l, r, t[v].r, tm + 1, tr);
}
int a[N + 1], b[N + 1];
Mint A[4][N + 1], B[4][N + 1], pw[N + 1];
vector<int> e = {0};
int pos(int x) {
return lower_bound(all(e), x) - e.begin();
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
pw[0] = 1;
Mint ans = 0;
for (int i = 1; i <= n; ++i) {
pw[i] = pw[i - 1] * Mint(2);
}
for (int i = 1; i <= n; ++i) {
cin >> a[i];
ans = ans - Mint(a[i]) * pw[n - 1];
e.push_back(a[i]);
e.push_back(a[i] - 1);
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
ans = ans - Mint(b[i]) * pw[n - 1];
e.push_back(b[i]);
e.push_back(b[i] - 1);
}
make_unique(e);
++sz;
upd(0, 1);
for (int i = 1; i <= n; ++i) {
if (a[i] > b[i]) swap(a[i], b[i]);
A[1][i] = get(0, pos(a[i] - 1));
B[0][i] = get(0, pos(b[i]));
upd(pos(a[i]), A[1][i]);
upd(pos(b[i]), B[0][i]);
upd_mul(0, pos(a[i] - 1), 0);
upd_mul(pos(b[i] + 1), M, 2);
ans = ans + getH(0, M) * pw[n - i];
if (i == n) {
ans = ans - getH(0, M) * Mint(n);
}
}
upd_mul(0, M, 0);
upd(0, 1);
for (int i = n; i >= 1; --i) {
A[3][i] = get(0, pos(a[i] - 1));
B[2][i] = get(0, pos(b[i]));
upd(pos(a[i]), A[3][i]);
upd(pos(b[i]), B[2][i]);
upd_mul(0, pos(a[i] - 1), 0);
upd_mul(pos(b[i] + 1), M, 2);
ans = ans + getH(0, M) * pw[i - 1];
}
cout << ans << '\n';
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 84ms
memory: 702300kb
input:
4 1 1 1 1 2 2 2 2
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 56ms
memory: 700492kb
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: 59ms
memory: 699120kb
input:
1 1 2
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 75ms
memory: 699304kb
input:
2 1 1 2 2
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 32ms
memory: 699124kb
input:
3 1 1 1 2 2 2
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 63ms
memory: 700128kb
input:
3 1 1 1 3 2 3
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 46ms
memory: 699748kb
input:
3 2 1 1 3 2 3
output:
4
result:
ok single line: '4'
Test #8:
score: 0
Accepted
time: 31ms
memory: 699640kb
input:
3 1 1 2 3 2 3
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 59ms
memory: 700676kb
input:
4 1 1 2 2 2 2 1 1
output:
6
result:
ok single line: '6'
Test #10:
score: 0
Accepted
time: 44ms
memory: 699600kb
input:
3 1 4 4 3 1 1
output:
2
result:
ok single line: '2'
Test #11:
score: -8
Wrong Answer
time: 51ms
memory: 699408kb
input:
20 801072306 297281669 94099424 745640358 822582129 579751930 776707816 425952653 529794053 256263083 615445445 401366545 990263003 967996508 788867983 916880116 837997768 346996508 623409388 122077161 141734988 448434751 822901346 825591177 388082644 468025968 260356829 1164654 537396602 730502935 ...
output:
180683926
result:
wrong answer 1st lines differ - expected: '840988190', found: '180683926'
Subtask #2:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 48ms
memory: 700692kb
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:
782936760
result:
wrong answer 1st lines differ - expected: '164439470', found: '782936760'
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: 1680ms
memory: 710684kb
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: 1656ms
memory: 711828kb
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: 1673ms
memory: 711776kb
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: 1677ms
memory: 710672kb
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%