| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 729483 | MilosMilutinovic | Rectangles (IOI19_rect) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// todo
#include "rect.h"
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
PII goL[2505][2505], goR[2505][2505], goU[2505][2505], goD[2505][2505];
vector<PII> ver[2505], hor[2505];
LL count_rectangles(vector<vector<int>> a)
{
int n = (int)a.size(), m = (int)a[0].size();
rep(i, n) {
vector<int> stk;
rep(j, m) {
while(!stk.empty() && a[i][j] > a[i][stk.back()]) stk.pop_back();
goL[i][j] = MP(i, stk.empty() ? -1 : stk.back());
stk.push_back(j);
}
}
rep(i, n) {
vector<int> stk;
for(int j = m - 1; j >= 0; j--) {
while(!stk.empty() && a[i][j] > a[i][stk.back()]) stk.pop_back();
goR[i][j] = MP(i, stk.empty() ? -1 : stk.back());
stk.push_back(j);
}
}
rep(j, m) {
vector<int> stk;
rep(i, n) {
while(!stk.empty() && a[i][j] > a[stk.back()][j]) stk.pop_back();
goU[i][j] = MP(stk.empty() ? -1 : stk.back(), j);
stk.push_back(i);
}
}
rep(j, m) {
vector<int> stk;
for(int i = n - 1; i >= 0; i--) {
while(!stk.empty() && a[i][;j] > a[stk.back()][j]) stk.pop_back();
goD[i][j] = MP(stk.back() ? -1 : stk.back(), j);
stk.push_back(i);
}
}
rep(i, n) rep(j, m) {
if(goL[i][j].second != -1) ver[i].push_back(MP(goL[i][j].second, j));
if(goR[i][j].second != -1) ver[i].push_back(MP(j, goR[i][j].second));
}
}
