QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722454 | #8546. Min or Max 2 | guosoun | TL | 4038ms | 4176kb | C++17 | 2.6kb | 2024-11-07 19:06:25 | 2024-11-07 19:06:25 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
template <int n>
struct matrix {
std::array<std::bitset<n>, n> a;
matrix() : a{} {}
matrix operator*(matrix b) {
matrix ret;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (a[i][j]) ret.a[i] |= b.a[j];
return ret;
}
};
template <class T>
struct sgt {
int n;
std::vector<T> tr;
int ls(int i) { return i << 1; }
int rs(int i) { return i << 1 | 1; }
void update(int i, int l, int r, int p, T x) {
if (l == r) return tr[i] = x, void();
int mid = (l + r) >> 1;
if (p <= mid)
update(ls(i), l, mid, p, x);
else
update(rs(i), mid + 1, r, p, x);
tr[i] = tr[ls(i)] * tr[rs(i)];
}
T query() { return tr[1]; }
void update(int p, T v) { update(1, 0, n - 1, p, v); }
sgt() {}
sgt(int n) : n(n), tr(n * 4) {}
};
struct checker {
int n, x, y;
std::vector<int> a, b, pa, pb;
sgt<matrix<9>> tr;
void update(int i) {
int av = a[i] < x ? 0 : a[i] == x ? 1 : 2;
int bv = b[i] < y ? 0 : b[i] == y ? 1 : 2;
matrix<9> ma;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
ma.a[i * 3 + j][std::min(i, av) * 3 + std::min(j, bv)] = 1;
ma.a[i * 3 + j][std::max(i, av) * 3 + std::max(j, bv)] = 1;
}
tr.update(i, ma);
}
bool query(int qx, int qy) {
while (x > qx) --x, update(pa[x + 1]), update(pa[x]);
while (x < qx) ++x, update(pa[x - 1]), update(pa[x]);
while (y > qy) --y, update(pb[y + 1]), update(pb[y]);
while (y < qy) ++y, update(pb[y - 1]), update(pb[y]);
int av = a[0] < x ? 0 : a[0] == x ? 1 : 2;
int bv = b[0] < y ? 0 : b[0] == y ? 1 : 2;
return tr.query().a[av * 3 + bv][1 * 3 + 1];
}
checker(std::vector<int> a, std::vector<int> b)
: n(a.size()), x(0), y(0), a(a), b(b), pa(n + 1), pb(n + 1) {
tr = sgt<matrix<9>>(n);
for (int i = 0; i < n; i++) pa[a[i]] = i, pb[b[i]] = i, update(i);
}
};
void mian() {
int n;
std::cin >> n;
std::vector<int> a(n), b(n);
for (auto &x : a) std::cin >> x;
for (auto &x : b) std::cin >> x;
checker chk(a, b);
std::vector<int> ans(n);
int i = 1, j = 1;
while (i <= n || j <= n) {
assert(chk.query(i, j)), ans[std::abs(i - j)] += 1;
if (i < n && chk.query(i + 1, j)) i += 1;
else if (j < n && chk.query(i, j + 1)) j += 1;
else i += 1, j += 1;
}
for (int i : ans) std::cout << i << ' ';
std::cout << '\n';
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
int t;
std::cin >> t;
while (t--) mian();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
4 2 1 2 2 1 5 2 4 1 5 3 2 4 1 5 3 5 1 2 3 4 5 5 4 3 2 1 8 5 8 3 4 2 7 1 6 4 6 3 8 5 1 2 7
output:
2 0 5 0 0 0 0 2 2 2 2 0 5 5 2 2 1 0 0 0
result:
ok 20 numbers
Test #2:
score: 0
Accepted
time: 1747ms
memory: 3568kb
input:
66664 7 4 2 6 5 7 1 3 6 5 3 1 4 7 2 10 6 8 10 7 5 1 4 3 9 2 5 10 3 8 6 7 2 9 1 4 9 3 2 4 8 7 6 9 1 5 8 1 2 9 6 7 4 3 5 10 4 3 9 6 7 2 10 1 8 5 3 5 4 1 2 7 10 9 6 8 5 3 4 1 2 5 5 1 3 2 4 5 2 4 3 5 1 2 3 1 4 5 6 2 6 1 3 4 5 6 4 5 1 3 2 10 10 1 2 7 5 8 4 3 9 6 9 4 2 3 6 1 7 8 5 10 5 1 2 4 5 3 4 1 2 5 3...
output:
4 4 2 2 1 0 0 5 6 3 2 2 1 0 0 0 0 5 6 3 2 1 0 0 0 0 4 4 4 3 2 1 0 0 0 0 5 3 0 0 0 2 2 2 2 0 3 3 3 1 0 0 5 7 4 2 1 0 0 0 0 0 5 2 0 0 0 6 3 0 0 0 0 3 3 2 0 0 5 4 2 1 0 0 0 3 2 3 1 0 0 4 6 3 0 0 0 0 3 4 3 2 1 0 0 3 2 2 2 2 2 2 1 0 4 5 3 1 0 0 0 3 4 3 2 3 3 1 0 0 0 8 5 0 0 0 0 0 0 7 8...
result:
ok 499999 numbers
Test #3:
score: 0
Accepted
time: 3069ms
memory: 3856kb
input:
6690 72 31 50 47 60 24 33 72 49 5 26 17 65 40 64 8 2 19 51 30 58 71 16 66 56 9 48 21 61 44 59 22 11 15 28 68 29 1 27 37 41 23 6 20 62 43 34 18 4 70 54 13 12 36 35 25 67 45 38 69 53 42 63 55 3 14 7 57 32 52 39 10 46 31 9 7 56 32 64 39 33 62 24 49 54 18 53 43 40 4 28 37 2 61 47 10 26 23 16 22 30 11 60...
output:
7 11 7 5 6 6 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 2 2 2 3 4 4 4 4 4 3 1 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 3 4 6 6 4 4 3 2 2 2 2 2 2 2 2 2 3 4 4 4 4 4 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 6 6 7 8 7 6 7 8 8 7 5 4 4 3 2 2 2...
result:
ok 499981 numbers
Test #4:
score: 0
Accepted
time: 4038ms
memory: 4176kb
input:
666 775 98 357 198 407 409 200 454 585 319 622 366 264 710 91 765 78 32 528 335 101 469 204 312 382 276 613 231 342 327 324 441 544 413 299 494 393 349 611 211 702 165 297 320 284 401 530 317 567 142 742 447 482 662 126 506 273 362 328 555 416 206 604 589 305 99 114 291 131 386 75 670 280 704 189 43...
output:
11 20 20 20 19 18 18 18 18 18 18 18 18 18 18 18 18 17 16 16 16 16 16 16 16 16 16 16 16 16 16 15 14 14 14 14 13 12 12 12 12 12 12 12 12 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 8 8 8 8 7 6 6 6 6 6 6 6 6 6 6 6 6 ...
result:
ok 500000 numbers
Test #5:
score: -100
Time Limit Exceeded
input:
65 9836 5216 2035 5946 2744 9708 9116 1184 2000 4650 569 2428 585 3406 8146 6809 875 9131 9092 5998 2088 8393 9447 7766 4990 3903 7730 3426 6726 2029 4208 1546 4639 997 1428 2357 8630 7552 3531 7241 3530 4548 7310 3205 3508 9764 8929 4781 5702 3777 670 7384 1049 1707 4544 1637 9349 2427 3338 634 596...
output:
8 13 12 11 10 10 10 10 10 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 10 8 8 8 8 8 8 8 8 8 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6...