Submission #152083

# Submission time Handle Problem Language Result Execution time Memory
152083 2019-09-06T10:30:42 Z oolimry Rectangles (IOI19_rect) C++14
0 / 100
22 ms 16220 KB
#include <bits/stdc++.h>
 
using namespace std;
 /*
class Segment{
public:
	vector<int> tree;
	int n;
	
	void create(int nn){
		n = nn;
		for(int i = 0;i < 2 * n + 5;i++){
			tree.push_back(-1);
		}
	}
	
	void update(int i, int x){
		i += n;
		while(i > 0){
			tree[i] = max(tree[i],x);
			i >>= 1;
		}
	}
	
	int query(int l, int r){
		int ans = -1;
		for(l += n,r += n;l < r;l >>= 1, r >>= 1){
			if(l&1){
				ans = max(ans,tree[l]);
				l++;
			}
			if(r&1){
				r--;
				ans = max(ans,tree[r]);
			}
		}
		return ans;
	}
};
*/
static int tree[1405][1405];
inline void update(int t, int i, int x){
	i += 700;
	while(i > 0){
		tree[t][i] = max(tree[t][i],x);
		i >>= 1;
	}
}

inline int query(int t, int l, int r){
	int ans = -1;
	for(l += 700,r += 700;l < r;l >>= 1, r >>= 1){
		if(l&1){
			ans = max(ans,tree[t][l]);
			l++;
		}
		if(r&1){
			r--;
			ans = max(ans,tree[t][r]);
		}
	}
	return ans;
}
 
 
long long count_rectangles(std::vector<std::vector<int> > a) {
	int rows = a.size();
	int cols = a[0].size();
	long long ans = 0;
	//Segment hori[rows];
	//Segment vert[cols];
 
	set<long long> answers;
	for(int c = 0;c < cols;c++){
		//vert[c].create(rows);
	}
	for(int r = 0;r < rows;r++){
		//hori[r].create(cols);
 
	}
	for(int r = 0;r < rows;r++){
		for(int c = 0;c < cols;c++){
			//hori[r].update(c,a[r][c]);
			//vert[c].update(r,a[r][c]);
			update(r,c,a[r][c]);
			update(rows+c,r,a[r][c]);
		}
	}
	typedef pair<int,int> ii;
	typedef pair<int,ii> iii;
	
	vector<iii> points;
	for(int r = 0;r < rows;r++){
		for(int c = 0;c < cols;c++){
			points.push_back(iii(a[r][c],ii(r,c)));
		}
	}
	
	sort(points.begin(),points.end());
	stack<ii> arr;
	for(int p = 0;p < points.size();p++){
		int rr = points[p].second.first;
		int cc = points[p].second.second;
		//cout << rr << " " << cc << " " << a[rr][cc] << "\n";
		arr.push(ii(rr,cc));
		if(p == points.size()-1 || points[p].first != points[p+1].first){
			while(!arr.empty()){
				int r = arr.top().first;
				int c = arr.top().second;
				arr.pop();
				if(r == 0 || r == rows - 1 || c == 0 || c == cols-1) continue;
				
				//if(hhh[r].query(c) != 0) continue;
				
				int lr = r, hr = r, lc = c, hc = c; //exclusive
				
				while(lr > 0){
					if(a[lr][c] > a[r][c]) break;
					lr--;
				}
				
				while(hr < rows-1){
					if(a[hr][c] > a[r][c]) break;
					hr++;
				}
				
				while(lc > 0){
					if(a[r][lc] > a[r][c]) break;
					lc--;
				}
				
				while(hc < cols-1){
					if(a[r][hc] > a[r][c]) break;
					hc++;
				}
				
				bool can = true;
				for(int sr = lr+1;sr < hr;sr++){
					int value = query(sr,lc+1,hc);
					if(value >= a[sr][lc] || value >= a[sr][hc]){
						can = false;
						break;
					}
				}
				for(int sc = lc+1;sc < hc;sc++){
					int value = query(sc,lr+1,hc);
					if(value >= a[lr][sc] || value >= a[hr][sc]){
						can = false;
						break;
					}
				}
				
				if(can){
					
					long long vvv = lr * 1000000000ll;
					vvv += hr * 1000000ll;
					vvv += lc * 1000ll;
					vvv += hc;
					answers.insert(vvv);
				}
				
				//cout << r << " " << c << " " << lr << " " << hr << " " << lc << " " << hc << "\n";
			}
			
		}
	}
	return answers.size();
}

Compilation message

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:101:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int p = 0;p < points.size();p++){
                ~~^~~~~~~~~~~~~~~
rect.cpp:106:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(p == points.size()-1 || points[p].first != points[p+1].first){
      ~~^~~~~~~~~~~~~~~~~~
rect.cpp:69:12: warning: unused variable 'ans' [-Wunused-variable]
  long long ans = 0;
            ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 16220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -