이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include <bits/stdc++.h>
#define N 505
using namespace std;
struct BIT2D{
	vector<vector<int>> bit;
	int n;
	BIT2D(){
		n = N;
		bit.assign(N,vector<int>(N,0));
	}
	void upd(int x,int y,int val){
		for(;x < n;x += x & -x){
			for(;y < n;y += y & -y){
				bit[x][y] += val;
			}
		}
	}
	int get(int x,int y){
		int ret = 0;
		for(;x > 0;x -= x & -x){
			for(;y > 0;y -= y & -y){
				ret += bit[x][y];
			}
		}
		return ret;
	}
};
map<int,int> dwn[N][N];
short rght[N][N][N];
long long count_rectangles(vector<vector<int>> a){
	long long ans = 0;
	int n = a.size();
	int m = a[0].size();
	for(int i = m-1;i>=0;i--){
		for(int j = 0;j<n-1;j++){
			int maxi = a[j+1][i];
			for(int c = j+2;c<n && maxi < a[j][i];c++){
				if(maxi >= a[c][i])
					continue;
				rght[j][i][c] = 1;
				rght[j][i][c] += rght[j][i + 1][c];
				maxi = a[c][i];
			}
		}
	}
	int cnt = 0;
	BIT2D t;
	for(int i = n-1;i>0;i--){
		vector<int> nxt(m + 5,m);
		stack<int> st;
		st.push(m-1);
		for(int j = m-2;j>=0;j--){
			while(st.size() && a[i][st.top()] <= a[i][j])
				st.pop();
			if(st.size())
				nxt[j] = st.top();
			st.push(j);
			for(int c = nxt[j + 1];c < m;c = nxt[j]){
				dwn[i][j][c] = 1 + dwn[i + 1][j][c];
				for(int d = i + 1;d <= i + dwn[i][j][c];d++){
					ans += (j + 1 + rght[i-1][j+1][d]) >= c; 
				}
				if(a[i][c] <= a[i][j])
					break;
			}
		}
	}
	assert(cnt <= n * m);
	return ans;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |