QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#553191 | #9240. Mosaic | dalao_see_me# | 5 | 137ms | 25512kb | C++14 | 4.1kb | 2024-09-08 10:23:08 | 2024-09-08 10:23:09 |
Judging History
answer
#include "mosaic.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 5;
typedef pair <int, int> pii;
int n, q;
int a[N], b[N], col[N];
struct Node {
int l, r, id, w;
} ;
vector <Node> t[N];
vector <pii> S;
struct Mat {
int n, m;
LL a[3][3];
Mat operator + (const Mat &B) {
Mat res; res.n = n; res.m = m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
res.a[i][j] = a[i][j] + B.a[i][j];
return res;
}
Mat operator * (const Mat &B) {
Mat res; res.n = n; res.m = B.m;
memset(res.a, 0, sizeof(res.a));
for (int i = 0; i < n; i++)
for (int k = 0; k < m; k++)
for (int j = 0; j < B.m; j++)
res.a[i][j] += a[i][k] * B.a[k][j];
return res;
}
} clr, rev, upd;
struct Seg {
#define lx x << 1
#define rx x << 1 | 1
Mat t[N << 2], tag[N << 2];
void upd(int x, const Mat &w) {
t[x] = t[x] * w;
tag[x] = tag[x] * w;
}
void pushup(int x) {
t[x] = t[lx] + t[rx];
}
void pushdown(int x) {
upd(lx, tag[x]);
upd(rx, tag[x]);
tag[x] = clr;
}
void build(int x, int L, int R) {
tag[x] = clr;
if (L == R) {
t[x].a[0][0] = t[x].a[0][1] = a[L]; t[x].a[0][2] = 1;
t[x].n = 1; t[x].m = 3; return;
}
int mid = L + R >> 1;
build(lx, L, mid);
build(rx, mid + 1, R);
pushup(x);
}
void modify(int x, int pos, int w, int L, int R) {
if (L == R) return void(t[x].a[0][1] = w);
pushdown(x);
int mid = L + R >> 1;
if (pos <= mid) modify(lx, pos, w, L, mid);
else modify(rx, pos, w, mid + 1, R);
pushup(x);
}
void change(int x, int l, int r, const Mat &w, int L, int R) {
if (l <= L && R <= r) return upd(x, w);
pushdown(x);
int mid = L + R >> 1;
if (l <= mid) change(lx, l, r, w, L, mid);
if (r > mid) change(rx, l, r, w, mid + 1, R);
pushup(x);
}
LL query(int x, int l, int r, int L, int R) {
if (l <= L && R <= r) return t[x].a[0][0];
pushdown(x);
int mid = L + R >> 1; LL res = 0;
if (l <= mid) res += query(lx, l, r, L, mid);
if (r > mid) res += query(rx, l, r, mid + 1, R);
return res;
}
} seg;
vector <LL> mosaic(vector <int> X, vector <int> Y, vector <int> T, vector <int> B, vector <int> L, vector <int> R) {
n = X.size(); q = T.size(); vector <LL> Ans(q);
for (int i = 0; i < n; i++) a[i + 1] = X[i], b[i + 1] = Y[i];
for (int i = 0; i < q; i++) {
Node w; w.l = L[i] + 1; w.r = R[i] + 1; w.id = i;
if (T[i]) {
w.w = -1;
t[T[i]].push_back(w);
}
w.w = 1; t[B[i] + 1].push_back(w);
}
for (int i = 2; i <= n; i++) S.push_back(make_pair(i, i)), col[i] = a[i];
memset(clr.a, 0, sizeof(clr.a));
clr.n = clr.m = 3; clr.a[0][0] = clr.a[1][1] = clr.a[2][2] = 1;
rev = clr; rev.a[1][1] = -1; rev.a[2][1] = 1; upd = clr; upd.a[1][0] = 1;
seg.build(1, 1, n);
for (auto p : t[1]) Ans[p.id] += p.w * seg.query(1, p.l, p.r, 1, n);
for (int i = 2; i <= n; i++) {
int c = b[i], lst = 0; seg.modify(1, 1, c, 1, n);
vector <pii> tmp;
for (auto p : S) {
if (col[p.first]) {
seg.change(1, p.first, p.second, rev, 1, n);
col[p.first] = 0;
if (c == col[p.first] && lst) {
tmp.push_back(make_pair(lst, p.first - 1));
lst = p.first;
}
if (!lst) lst = p.first;
c = col[p.first] ^ ((p.second - p.first) & 1);
}
else {
if (!c) {
seg.change(1, p.first, p.second, rev, 1, n);
col[p.first] = 1;
if (c == col[p.first] && lst) {
tmp.push_back(make_pair(lst, p.first - 1));
lst = p.first;
}
if (!lst) lst = p.first;
c = col[p.first] ^ ((p.second - p.first) & 1);
}
else {
if (p.first < p.second) seg.change(1, p.first + 1, p.second, rev, 1, n), col[p.first + 1] = 0;
if (p.first < p.second) {
if (!lst) tmp.push_back(make_pair(p.first, p.first));
else tmp.push_back(make_pair(lst, p.first));
}
if (p.first == p.second) c = 0, lst = p.first;
else c = (p.second - p.first + 1) & 1, lst = p.first + 1;
}
}
}
if (lst) tmp.push_back(make_pair(lst, n)); swap(S, tmp);
seg.change(1, 1, n, upd, 1, n);
for (auto p : t[i]) Ans[p.id] += p.w * seg.query(1, p.l, p.r, 1, n);
}
return Ans;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 2ms
memory: 12012kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 1 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 0 0 0 0 0 0 0 0 0 0
result:
ok
Test #2:
score: 5
Accepted
time: 1ms
memory: 12100kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 1 1 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 1 1 1 1 1 1 1 1 1 1
result:
ok
Test #3:
score: 5
Accepted
time: 1ms
memory: 12036kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 0 1 0 10 1 1 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 1 1 0 0 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 1 1 1 2 2 0 2 1 1 1
result:
ok
Test #4:
score: 5
Accepted
time: 0ms
memory: 12020kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 0 1 0 10 0 1 1 1 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 1 0 1 0 0 1 1 0 0
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 1 2 1 1 2 1 1 1 1 0
result:
ok
Test #5:
score: 5
Accepted
time: 2ms
memory: 14128kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 0 1 0 0 10 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 0 1 0 0 0 0 1 1 1 1
result:
ok
Test #6:
score: 5
Accepted
time: 2ms
memory: 14332kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 1 1 0 10 0 0 0 1 0 0 0 1 1 1 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 0
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2 2 0 2 1 1 0 1 1 1
result:
ok
Test #7:
score: 5
Accepted
time: 2ms
memory: 14100kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 0 0 0 1 10 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 0 1 1 1 0 0 0 1 1 1
result:
ok
Test #8:
score: 5
Accepted
time: 0ms
memory: 12324kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 0 1 1 10 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2 1 1 0 1 0 2 0 1 2
result:
ok
Test #9:
score: 5
Accepted
time: 2ms
memory: 12056kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 0 1 0 1 10 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 1 0 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2 2 0 2 1 2 1 0 1 2
result:
ok
Test #10:
score: 5
Accepted
time: 1ms
memory: 12028kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 2 1 1 1 1 10 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 1 1
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 2 2 2 3 1 3 3 1 3 0
result:
ok
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #11:
score: 0
Wrong Answer
time: 3ms
memory: 14116kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 199 0 0 1 0 0 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 0 0 1...
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 1265 5793 1053 486 11928 1422 2002 4959 819 2134 42 494 800 6437 6148 713 45 14 204 473 3526 134 4655 56 1600 1400 91 1645 1232 5909 6478 3068 72 2907 1269 67 4189 2280 365 3192 497 1845 655 1970 855 6048 2214 2394 312 3996 2330 5046 1110 1692 2384 2035 88 11248 1...
result:
wrong answer 3rd lines differ - on the 1st token, expected: '1078', found: '1265'
Subtask #3:
score: 0
Time Limit Exceeded
Test #18:
score: 0
Time Limit Exceeded
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 199999 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 1 0 0 0 1 1 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0 0 0 0 ...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 137ms
memory: 25512kb
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 200000 1 7 0 4 3 4 3 4 3 6 2 5 4 5 6 7 5 7 2 8 0 6 4 7 0 5 6 7 1 3 9 9 6 9 1 7 2 9 4 6 4 4 6 7 0 1 8 8 7 7 0 3 0 4 1 7 2 2 0 9 3 9 4 6 3 9 0 9 1 8 4 6 4 5 5 7 0 6 2 3 2 3 0 6 1 9 8 8 2 4 3 4 3 6 2 9 3 9 2 7 1 3 0 3 0 8 2 4 3...
output:
Wm5rkGNobnYjFI7TIY17RAm6FAQ2LlO9 OK 14 2 8 2 10 12 5 2 16 8 1 0 2 16 5 7 35 8 4 6 6 4 3 16 21 6 8 6 7 14 16 7 9 3 6 18 6 5 8 10 15 27 2 5 14 10 20 4 0 16 6 9 25 1 0 5 8 4 1 5 0 0 6 4 21 36 10 2 7 7 9 14 12 7 4 6 10 6 4 16 8 15 8 5 2 9 24 3 2 5 7 16 24 15 10 2 4 3 0 20 20 7 0 6 3 12 18 8 40 8 8 8 9 8...
result:
wrong answer 11th lines differ - on the 1st token, expected: '14', found: '16'
Subtask #6:
score: 0
Time Limit Exceeded
Test #42:
score: 0
Time Limit Exceeded
input:
njJ9Z7VxxKGR6SUcJMgdzy3qMz4JZ1Tq 199999 0 1 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 1 1 0 0 0 0 1 0 1 ...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%