Submission #561046

#TimeUsernameProblemLanguageResultExecution timeMemory
561046hoanghq2004Rectangles (IOI19_rect)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "rect.h"

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2510;

int up[N][N], down[N][N], lft[N][N], rgt[N][N];

int count_rectangles(vector <vector <int>> a) {
    int n = a.size();
    int m = a[0].size();
    for (int i = 0; i < n; ++i) {
        stack <int> stk;
        for (int j = 0; j < m; ++j) {
            while (stk.size() && a[i][j] >= a[i][stk.top()]) {
                rgt[i][stk.top()] = j - 1;
                stk.pop();
            }
            stk.push(j);
        }
        while (stk.size()) {
            rgt[i][stk.top()] = m - 1;
            stk.pop();
        }
        for (int j = m - 1; j >= 0; --j) {
            while (stk.size() && a[i][j] >= a[i][stk.top()]) {
                lft[i][stk.top()] = j + 1;
                stk.pop();
            }
            stk.push(j);
        }
        while (stk.size()) {
            lft[i][stk.top()] = 0;
            stk.pop();
        }
    }
    for (int i = 0; i < m; ++i) {
        stack <int> stk;
        for (int j = 0; j < n; ++j) {
            while (stk.size() && a[j][i] >= a[stk.top()][i]) {
                down[stk.top()][i] = j - 1;
                stk.pop();
            }
            stk.push(j);
        }
        while (stk.size()) {
            down[stk.top()][i] = n - 1;
            stk.pop();
        }
        for (int j = n - 1; j >= 0; --j) {
            while (stk.size() && a[j][i] >= a[stk.top()][i]) {
                up[stk.top()][i] = j + 1;
                stk.pop();
            }
            stk.push(j);
        }
        while (stk.size()) {
            up[stk.top()][i] = 0;
            stk.pop();
        }
    }
    auto check = [&](int x, int y, int u, int v) {
        for (int i = x; i <= u; ++i)
            if (rgt[i][y - 1] < v || lft[i][v + 1] > y) return 0;
        for (int i = y; i <= v; ++i)
            if (down[x - 1][i] < u || up[u + 1][i] > x) return 0;
        return 1;
    };
    int ans = 0;
    for (int x = 1; x < n - 1; ++x)
        for (int y = 1; y < m - 1; ++y)
            for (int u = x; u < n - 1; ++u)
                for (int v = y; v < m - 1; ++v)
                    ans += check(x, y, u, v);
    return ans;
}
//
//int main() {
//	int n, m;
//    cin >> n >> m;
//	vector<vector<int>> a(n, vector<int>(m));
//	for (int i = 0; i < n; i++)	{
//		for (int j = 0; j < m; j++) {
//            cin >> a[i][j];
//		}
//	}
//	cout << count_rectangles(a) << '\n';
//}

Compilation message (stderr)

rect.cpp:18:5: error: ambiguating new declaration of 'int count_rectangles(std::vector<std::vector<int> >)'
   18 | int count_rectangles(vector <vector <int>> a) {
      |     ^~~~~~~~~~~~~~~~
In file included from rect.cpp:6:
rect.h:7:11: note: old declaration 'long long int count_rectangles(std::vector<std::vector<int> >)'
    7 | long long count_rectangles(std::vector<std::vector<int> > a);
      |           ^~~~~~~~~~~~~~~~