# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
726556 | LittleCube | Rectangles (IOI19_rect) | C++14 | 5086 ms | 812168 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-loops")
#ifndef EVAL
#include "grader.cpp"
#endif
#include "rect.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
struct BIT
{
int bit[2501], N;
vector<int> p;
int getP(int x)
{
return lower_bound(p.begin(), p.end(), x) - p.begin();
}
void init()
{
p.emplace_back(0);
sort(p.begin(), p.end());
p.resize(unique(p.begin(), p.end()) - p.begin());
N = p.size();
for (int i = 1; i < N; i++)
bit[i] = 0;
}
void modify(int pos, int val)
{
pos = getP(pos);
for (int i = pos; i < N; i += (i & -i))
bit[i] += val;
}
int query(int pos)
{
pos = getP(pos);
int ans = 0;
for (int i = pos; i; i -= (i & -i))
ans += bit[i];
return ans;
}
} bit[2500];
int N, M;
pii table[2500][2500];
vector<pii> ver[2500], hor[2500];
vector<tuple<int, int, int, int>> event[2500];
ll ans;
ll cnt;
void add_query(int l, int r, pii range)
{
if (range == pii(-1, -1))
return;
for (int i = range.F - 1; i <= range.S + 1; i++)
{
cnt++;
event[l].emplace_back(make_tuple(r, 0, i, range.S + 1));
}
}
void add_modify(pii range, int u, int d)
{
if (range == pii(-1, -1))
return;
for (int i = range.F - 1; i <= range.S + 1; i++)
{
cnt++;
event[i].emplace_back(make_tuple(range.S + 1, 1, u, d));
}
}
ll count_rectangles(vector<vector<int>> a)
{
N = a.size(), M = a[0].size();
if (N <= 2 || M <= 2)
return 0;
for (int i = 1; i + 1 < N; i++)
{
vector<pii> mono;
for (int j = 0; j < M; j++)
{
while (!mono.empty() && mono.back().F < a[i][j])
{
if (j - mono.back().S >= 2)
ver[i].emplace_back(pii(mono.back().S, j));
mono.pop_back();
}
if (!mono.empty())
if (j - mono.back().S >= 2)
ver[i].emplace_back(pii(mono.back().S, j));
if (!mono.empty() && mono.back().F == a[i][j])
mono.back().S = j;
else
mono.emplace_back(pii(a[i][j], j));
}
}
for (int i = 0; i < M; i++)
for (int j = 0; j < M; j++)
table[i][j] = pii(-1, -1);
for (int i = 1; i + 1 < N; i++)
for (auto [x, y] : ver[i])
if (table[x][y].S == i - 1)
table[x][y].S++;
else
{
add_query(x, y, table[x][y]);
table[x][y] = pii(i, i);
}
for (int i = 0; i < M; i++)
for (int j = 0; j < M; j++)
add_query(i, j, table[i][j]);
for (int i = 1; i + 1 < M; i++)
{
vector<pii> mono;
for (int j = 0; j < N; j++)
{
while (!mono.empty() && mono.back().F < a[j][i])
{
if (j - mono.back().S >= 2)
hor[i].emplace_back(pii(mono.back().S, j));
mono.pop_back();
}
if (!mono.empty())
if (j - mono.back().S >= 2)
hor[i].emplace_back(pii(mono.back().S, j));
if (!mono.empty() && mono.back().F == a[j][i])
mono.back().S = j;
else
mono.emplace_back(pii(a[j][i], j));
}
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
table[i][j] = pii(-1, -1);
for (int i = 1; i + 1 < M; i++)
for (auto [x, y] : hor[i])
if (table[x][y].S == i - 1)
table[x][y].S++;
else
{
add_modify(table[x][y], x, y);
table[x][y] = pii(i, i);
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
add_modify(table[i][j], i, j);
for (int i = 0; i < M; i++)
{
sort(event[i].begin(), event[i].end(), greater<>());
for (int i = 0; i < N; i++)
bit[i].p.clear();
for (auto [_, t, l, r] : event[i])
bit[l].p.emplace_back(r);
for (int i = 0; i < N; i++)
bit[i].init();
for (auto [_, t, l, r] : event[i])
{
if (t == 1)
bit[l].modify(r, 1);
else
ans += bit[l].query(r);
}
}
assert(cnt <= 6 * N * M);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |