이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//#pragma GCC target("avx2")
//#pragma GCC optimization("unroll-loops")
//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3")
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define make_unique(v) v.erase(unique(all(v)),v.end())
const int N=2506;
vector<int> ver[N][N],bn[N][N];
int en[N][N], sk[N][N];
long long count_rectangles(vector<vector<int> > a) {
	int n=a.size();
	int m=a[0].size();
	FORT(j,1,m-2){
		stack<pir> s;
		s.push({INT_MAX,-1});
		int qan=0;
		FOR(i,n){
			while(s.top().fr<=a[i][j]){
				if (s.top().sc==i-1){
					s.pop();
					continue;
				}
				ver[i-1][j].ad(s.top().sc+1);
				bn[i-1][s.top().sc+1].ad(j);
				qan++;
				
				s.pop();
			}
			s.push({a[i][j],i});
		}
		while(s.size()!=1)s.pop();
		//assert(s.top().fr==INT_MAX);
		FORD(i,n){
			while(s.top().fr<a[i][j]){
				if (s.top().sc==i+1){
					s.pop();
					continue;
				}
				ver[s.top().sc-1][j].ad(i+1);
				bn[s.top().sc-1][i+1].ad(j);
				qan++;
				assert(s.top().sc==2 && i==0);
				s.pop();
			}
			s.push({a[i][j],i});
		}
		/*
		if (a[0][j]>a[1][j] && a[2][j]>a[1][j]);
		else assert(qan==0);*/
	}
	ll ans=0;
	FORT(i,1,n-2){
		stack<pir> s;
		s.push({INT_MAX,-1});
		FOR(j,m){
			while(s.top().fr<=a[i][j]){
				
				//cout<<i<<" hey "<<s.top().fr<<" "<<s.top().sc<<" "<<a[i][j]<<endl;
				if (s.top().sc==j-1){
					s.pop();
					continue;
				}
				int l=s.top().sc+1,r=j-1;
				
				//cout<<i<<" "<<l<<" "<<r<<" "<<sk[l][r]<<" "<<en[l][r]<<endl;
				if (en[l][r]!=i-1){
					sk[l][r]=i;
				}
				en[l][r]=i;
				trav(to,ver[i][l]){
					if (to<sk[l][r])continue;
					if (upper_bound(all(bn[i][to]),r)-lower_bound(all(bn[i][to]),l)==r-l+1)ans++;
				}
				s.pop();
			}
			s.push({a[i][j],j});
		}
		while(s.size()!=1)s.pop();
		FORD(j,m){
			while(s.top().fr<a[i][j]){
				//cout<<i<<" "<<s.top().fr<<" "<<s.top().sc<<" "<<a[i][j]<<endl;
				if (s.top().sc==j+1){
					s.pop();
					continue;
				}
				int l=j+1,r=s.top().sc-1;
				
				//cout<<"hey "<<i<<" "<<l<<" "<<r<<" "<<sk[l][r]<<" "<<en[l][r]<<endl;
				if (en[l][r]!=i-1){
					sk[l][r]=i;
				}
				en[l][r]=i;
				trav(to,ver[i][r]){
					if (to<sk[l][r])continue;
					if (upper_bound(all(bn[i][to]),r)-lower_bound(all(bn[i][to]),l)==r-l+1)ans++;
				}
				s.pop();
			}
			s.push({a[i][j],j});
		}
	}
	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... |