제출 #266781

#제출 시각아이디문제언어결과실행 시간메모리
266781dennisstarRectangles (IOI19_rect)C++17
72 / 100
5076 ms376968 KiB
#include <bits/stdc++.h>
#include "rect.h"
#define eb emplace_back
#define hsh(a, b, c) ((a)*6250000ll+(b)*2500ll+c)
using namespace std;
using ll = long long;

int N, M;
vector<ll> H, V;

long long count_rectangles(vector<vector<int>> a) {
	N=a.size(); M=a[0].size();
	vector<vector<int>> l, r, u, d;
	for (int i=0; i<N; i++)
		l.eb(vector<int>(M, -1));
	r=u=d=l;

	for (int i=1; i<N-1; i++) {
		vector<int> st;
		for (int j=0; j<M; j++) {
			while (st.size()&&a[i][st.back()]<a[i][j]) st.pop_back();
			if (st.size()&&st.back()<j-1) H.eb(hsh(st.back(), j, i));
			st.eb(j);
		}
		st.clear();
		for (int j=M-1; j>=0; j--) {
			while (st.size()&&a[i][st.back()]<a[i][j]) st.pop_back();
			if (st.size()&&st.back()>j+1) H.eb(hsh(j, st.back(), i));
			st.eb(j);
		}
		st.clear();
		for (int j=0; j<M; j++) {
			while (st.size()&&a[i][st.back()]<=a[i][j]) st.pop_back();
			if (st.size()) l[i][j]=st.back();
			st.eb(j);
		}
		st.clear();
		for (int j=M-1; j>=0; j--) {
			while (st.size()&&a[i][st.back()]<=a[i][j]) st.pop_back();
			if (st.size()) r[i][j]=st.back();
			st.eb(j);
		}
	}

	for (int j=1; j<M-1; j++) {
		vector<int> st;
		for (int i=0; i<N; i++) {
			while (st.size()&&a[st.back()][j]<a[i][j]) st.pop_back();
			if (st.size()&&st.back()<i-1) V.eb(hsh(st.back(), i, j));
			st.eb(i);
		}
		st.clear();
		for (int i=N-1; i>=0; i--) {
			while (st.size()&&a[st.back()][j]<a[i][j]) st.pop_back();
			if (st.size()&&st.back()>i+1) V.eb(hsh(i, st.back(), j));
			st.eb(i);
		}
		st.clear();
		for (int i=0; i<N; i++) {
			while (st.size()&&a[st.back()][j]<=a[i][j]) st.pop_back();
			if (st.size()) u[i][j]=st.back();
			st.eb(i);
		}
		st.clear();
		for (int i=N-1; i>=0; i--) {
			while (st.size()&&a[st.back()][j]<=a[i][j]) st.pop_back();
			if (st.size()) d[i][j]=st.back();
			st.eb(i);
		}
	}

	sort(H.begin(), H.end());
	H.resize(unique(H.begin(), H.end())-H.begin());
	
	sort(V.begin(), V.end());
	V.resize(unique(V.begin(), V.end())-V.begin());

	vector<tuple<int, int, int, int>> A;
	for (int i=1; i<N-1; i++) for (int j=1; j<M-1; j++) {
		int L=l[i][j], R=r[i][j], U=u[i][j], D=d[i][j];
		if (L==-1||R==-1||U==-1||D==-1) continue;

		int b1=lower_bound(H.begin(), H.end(), hsh(L, R, U+1))-H.begin();
		if (b1>=H.size()||hsh(L, R, U+1)!=H[b1]) continue;
		b1+=D-U-2;
		if (b1>=H.size()||hsh(L, R, D-1)!=H[b1]) continue;

		b1=lower_bound(V.begin(), V.end(), hsh(U, D, L+1))-V.begin();
		if (b1>=V.size()||hsh(U, D, L+1)!=V[b1]) continue;
		b1+=R-L-2;
		if (b1>=V.size()||hsh(U, D, R-1)!=V[b1]) continue;

		A.eb(L, R, U, D);
	}

	sort(A.begin(), A.end());
	return unique(A.begin(), A.end())-A.begin();
}

컴파일 시 표준 에러 (stderr) 메시지

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:84:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   if (b1>=H.size()||hsh(L, R, U+1)!=H[b1]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:86:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   if (b1>=H.size()||hsh(L, R, D-1)!=H[b1]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:89:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   if (b1>=V.size()||hsh(U, D, L+1)!=V[b1]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:91:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |   if (b1>=V.size()||hsh(U, D, R-1)!=V[b1]) continue;
      |       ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...