#include "quality.h"
#include <bits/stdc++.h>
#define ub(x) (x&(-x))
using namespace std;
constexpr int VALMAX = 9000000;
int aib[VALMAX+5];
void Update (int pos, int val) {
for (int i = pos; i <= VALMAX; i += ub(i))
aib[i] += val;
}
int Query (int pos) {
int S = 0;
for (; pos; pos -= ub(pos))
S += aib[pos];
return S;
}
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
for (int i = 0; i < H; ++ i )
for (int j = 0; j < W-1; ++ j )
Update(Q[i][j], 1);
int Min = R * C;
for (int i = 0; i < R - H + 1; ++ i ) {
if (i % 2 == 0) {
for (int j = W-1; j < C; ++ j ) {
for (int aux = i; aux < i + H; ++ aux )
Update(Q[aux][j], 1);
int st = 1, dr = R * C;
int ans = 0;
while (st <= dr) {
int mij = (st + dr) / 2;
int val = Query(mij-1);
if (val <= H * W / 2) {
st = mij + 1;
ans = mij;
}
else dr = mij - 1;
}
Min = min(Min, ans);
for (int aux = i; aux < i + H; ++ aux )
Update(Q[aux][j-W+1], -1);
}
if (i != R - H) {
for (int j = C - W + 1; j < C; ++ j ) {
Update(Q[i + H][j], 1);
Update(Q[i][j], -1);
}
}
}
else {
for (int j = C-W; j >= 0; -- j ) {
for (int aux = i; aux < i + H; ++ aux )
Update(Q[aux][j], 1);
int st = 1, dr = R * C;
int ans = 0;
while (st <= dr) {
int mij = (st + dr) / 2;
int val = Query(mij-1);
if (val <= H * W / 2) {
st = mij + 1;
ans = mij;
}
else dr = mij - 1;
}
Min = min(Min, ans);
for (int aux = i; aux < i + H; ++ aux )
Update(Q[aux][j+W-1], -1);
}
if (i != R - H) {
for (int j = 0; j < C-1; ++ j ) {
Update(Q[i+H][j], 1);
Update(Q[i][j], -1);
}
}
}
}
return Min;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |