QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133367 | #2672. Rectangles | bashkort | 0 | 1ms | 4192kb | C++20 | 4.7kb | 2023-08-02 02:56:39 | 2023-08-02 02:56:43 |
Judging History
answer
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
namespace SparseTable {
vector<vector<int>> mn;
void init(const vector<int> &a) {
int n = size(a), l = __lg(n) + !!(n & (n - 1));
mn.resize(l);
mn[0] = a;
for (int k = 1; k < l; ++k) {
mn[k].resize(n - (1 << k) + 1);
for (int i = 0; i < size(mn[i]); ++i) {
mn[k][i] = min(mn[k - 1][i], mn[k - 1][i + (1 << k - 1)]);
}
}
}
int rangeMin(int l, int r) {
int lg = __lg(r - l);
return min(mn[lg][l], mn[lg][r - (1 << lg)]);
}
}
ll count_rectangles(std::vector<std::vector<int>> a) {
const int n = size(a), m = size(a[0]);
if (n <= 2 || m <= 2) {
return 0;
}
vector LA(n, vector<int>(m, 0)), RA(n, vector<int>(m, m - 1));
vector UP(n, vector<int>(m, 0)), DOWN(n, vector<int>(m, n - 1));
vector<array<int, 4>> rect;
for (int t = 1; t >= 0; --t) {
for (int i = 1; i + 1 < n; ++i) {
vector<int> stk;
for (int j = 0; j < m; ++j) {
while (!stk.empty() && a[i][stk.back()] < a[i][j] + t) {
stk.pop_back();
}
if (!stk.empty()) {
LA[i][j] = stk.back();
}
stk.push_back(j);
}
stk.clear();
for (int j = m - 1; j >= 0; --j) {
while (!stk.empty() && a[i][stk.back()] < a[i][j] + t) {
stk.pop_back();
}
if (!stk.empty()) {
RA[i][j] = stk.back();
}
stk.push_back(j);
}
}
for (int j = 1; j + 1 < m; ++j) {
vector<int> stk;
for (int i = 0; i < n; ++i) {
while (!stk.empty() && a[stk.back()][j] < a[i][j]) {
stk.pop_back();
}
if (!stk.empty()) {
UP[i][j] = stk.back();
}
stk.push_back(i);
}
stk.clear();
for (int i = n - 1; i >= 0; --i) {
while (!stk.empty() && a[stk.back()][j] < a[i][j]) {
stk.pop_back();
}
if (!stk.empty()) {
DOWN[i][j] = stk.back();
}
stk.push_back(i);
}
}
if (t == 1) {
for (int i = 1; i + 1 < n; ++i) {
for (int j = 1; j + 1 < m; ++j) {
rect.push_back({UP[i][j], LA[i][j], DOWN[i][j], RA[i][j]});
}
}
}
}
sort(rect.begin(), rect.end());
rect.resize(unique(rect.begin(), rect.end()) - rect.begin());
int s = size(rect);
vector<int> alright(s, 1); // 0 - left (=> min), 1 - up (=> min), 2 - right, 3 - down
vector<vector<array<int, 4>>> rows(n), columns(m);
for (int i = 0; i < s; ++i) {
auto [x1, y1, x2, y2] = rect[i];
rows[x1].push_back({y1 + 1, y2, 1, i});
rows[x2].push_back({y1 + 1, y2, 3, i});
columns[y1].push_back({x1 + 1, x2, 0, i});
columns[y2].push_back({x1 + 1, x2, 2, i});
}
for (int i = 0; i < n; ++i) {
SparseTable::init(DOWN[i]);
for (auto [l, r, type, id] : rows[i]) {
if (type == 1) {
int got = SparseTable::rangeMin(l, r);
alright[i] &= got >= rect[id][3];
}
}
vector<int> init(UP[i]);
for (int &x : init) {
x = -x;
}
SparseTable::init(init);
for (auto [l, r, type, id] : rows[i]) {
if (type == 3) {
int got = -SparseTable::rangeMin(l, r);
alright[i] &= got <= rect[id][1];
}
}
}
for (int j = 0; j < m; ++j) {
vector<int> init(n);
for (int i = 0; i < n; ++i) {
init[i] = RA[i][j];
}
SparseTable::init(init);
for (auto [l, r, type, id] : columns[j]) {
if (type == 0) {
int got = SparseTable::rangeMin(l, r);
alright[id] &= got >= rect[id][2];
}
}
for (int i = 0; i < n; ++i) {
init[i] = -LA[i][j];
}
for (auto [l, r, type, id] : columns[j]) {
if (type == 2) {
int got = -SparseTable::rangeMin(l, r);
alright[id] &= got <= rect[id][0];
}
}
}
int ans = accumulate(alright.begin(), alright.end(), 0);
return ans;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3824kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 30 30 3996 3689 3664 3657 3646 3630 3621 3619 3609 3604 3601 3598 3584 3581 3574 3561 3554 3543 3537 3531 3522 3519 3505 3500 3498 3492 3476 3467 3460 3994 3993 3458 3451 3440 3431 3420 3395 3346 3333 3282 3268 3261 3241 3204 3168 3121 3103 3083 3076 2923 2872 28...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 28
result:
wrong answer 3rd lines differ - expected: '784', found: '28'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #53:
score: 0
Wrong Answer
time: 0ms
memory: 4192kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 3 2500 3999533 3994407 3992243 3991052 3990430 3988819 3987546 3985557 3983808 3983398 3982565 3981632 3981437 3979888 3979428 3978697 3978033 3975044 3973166 3972565 3971499 3970538 3969576 3969014 3968513 3968337 3966950 3965168 3964140 3963957 3962080 3961829 ...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 2497
result:
wrong answer 3rd lines differ - expected: '2498', found: '2497'
Subtask #6:
score: 0
Wrong Answer
Test #64:
score: 0
Wrong Answer
time: 1ms
memory: 3644kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 10 10 1 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 8
result:
wrong answer 3rd lines differ - expected: '2', found: '8'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%