Submission #155812

# Submission time Handle Problem Language Result Execution time Memory
155812 2019-09-30T16:16:11 Z vanic Rectangles (IOI19_rect) C++14
Compilation error
0 ms 0 KB
//#include "rect.h"
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <map>
#include <stack>
#include <set>
#include <array>
 
using namespace std;
 
typedef long long ll;
const int maxn=2003;
 
int n, m;
int l[maxn][maxn];
//vector < int > r[maxn][maxn], c[maxn][maxn];
unordered_map < ll, int > r, c;
int rind[maxn][maxn], cind[maxn][maxn];
pair < int, int > red[maxn][maxn], stup[maxn][maxn];
int bio2[maxn][maxn], bio3[maxn][maxn];
vector < array < int, 4 > > bio;

inline ll hashiraj(ll a, ll b, ll c){
	return a*maxn*maxn+b*maxn+c;
}
 
void upd1(int x){
	stack < pair < int, short > > q;
	q.push(make_pair(1e8, -1));
	for(int i=0; i<m; i++){
		while(q.top().first<=l[x][i]){
			q.pop();
		}
		red[x][i].first=q.top().second+1;
		q.push(make_pair(l[x][i], i));
	}
	while(!q.empty()){
		q.pop();
	}
	q.push(make_pair(1e8, m));
	for(int i=m-1; i>-1; i--){
		while(q.top().first<=l[x][i]){
			q.pop();
		}
		red[x][i].second=q.top().second-1;
		if(bio2[red[x][i].first][red[x][i].second]!=x+1){
			bio2[red[x][i].first][red[x][i].second]=x+1;
			rind[red[x][i].first][red[x][i].second]++;
			r[hashiraj(red[x][i].first, red[x][i].second, x)]=rind[red[x][i].first][red[x][i].second];
		}
		q.push(make_pair(l[x][i], i));
	}
}
 
void upd2(int x){
	stack < pair < int, short > > q;
	q.push(make_pair(1e8, -1));
	for(int i=0; i<n; i++){
		while(q.top().first<=l[i][x]){
			q.pop();
		}
		stup[i][x].first=q.top().second+1;
		q.push(make_pair(l[i][x], i));
	}
	while(!q.empty()){
		q.pop();
	}
	q.push(make_pair(1e8, n));
	for(int i=n-1; i>-1; i--){
		while(q.top().first<=l[i][x]){
			q.pop();
		}
		stup[i][x].second=q.top().second-1;
		if(bio3[stup[i][x].first][stup[i][x].second]!=x+1){
			bio3[stup[i][x].first][stup[i][x].second]=x+1;
			cind[stup[i][x].first][stup[i][x].second]++;
			c[hashiraj(stup[i][x].first, stup[i][x].second, x)]=cind[stup[i][x].first][stup[i][x].second];
		}
		q.push(make_pair(l[i][x], i));
	}
}
 
 
int binary(int x, vector < int > &l){
	int lo=0, hi=l.size(), mid;
	while(lo<hi){
		mid=(lo+hi)/2;
		if(l[mid]<x){
			lo=mid+1;
		}
		else{
			hi=mid;
		}
	}
	return lo;
}
 
void provjeri(int x, int y){
	int r1, r2, c1, c2;
	r1=red[x][y].first;
	r2=red[x][y].second;
	c1=stup[x][y].first;
	c2=stup[x][y].second;
	if(r1==0 || c1==0 || r2==m-1 || c2==n-1){
		return;
	}
//	int pos1=binary(c1, r[r1][r2]);
//	int pos2=binary(r1, c[c1][c2]);
	if(r[hashiraj(r1, r2, c2)]!=0 && r[hashiraj(r1, r2, c1)]!=0
	&& c[hashiraj(c1, c2, r2)]!=0 && c[hashiraj(c1, c2, r1)]!=0
	&& r[hashiraj(r1, r2, c2)]-r[hashiraj(r1, r2, c1)]==c2-c1 && c[hashiraj(c1, c2, r2)]-c[hashiraj(c1, c2, r1)]==r2-r1){
		bio.push_back({r1, r2, c1, c2});
	}
}
 
long long count_rectangles(vector < vector < int > > a){
	n=a.size();
	m=a[0].size();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			l[i][j]=a[i][j];
		}
	}
	for(int i=0; i<n; i++){
		upd1(i);
	}
	for(int i=0; i<m; i++){
		upd2(i);
	}
	for(int i=1; i<n-1; i++){
		for(int j=1; j<m-1; j++){
			provjeri(i, j);
		}
	}
	sort(bio.begin(), bio.end());
	bio.erase(unique(bio.begin(), bio.end()), bio.end());
	return bio.size();
}
 

int main(){
	scanf("%d%d", &n, &m);
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			scanf("%d", &l[i][j]);
		}
	}
	for(int i=0; i<n; i++){
		upd1(i);
	}
	for(int i=0; i<m; i++){
		upd2(i);
	}
	for(int i=1; i<n-1; i++){
		for(int j=1; j<m-1; j++){
			provjeri(i, j);
		}
	}
	sort(bio.begin(), bio.end());
	bio.erase(unique(bio.begin(), bio.end()), bio.end());
	printf("%d\n", (int)bio.size());
	return 0;
}

Compilation message

rect.cpp: In function 'int main()':
rect.cpp:145:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
rect.cpp:148:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &l[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
/tmp/cciRFkpH.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccs7UAZn.o:rect.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status