이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define gg exit(0);
const int N=2510;
int m,n;
int a[N][N];
int rt[N][N], lf[N][N], dw[N][N];
long long count_rectangles(vector<vector<int>> arr){
m=arr.size(), n=arr[0].size();
forinc(i,1,m) forinc(j,1,n) a[i][j]=arr[i-1][j-1];
forinc(i,1,m){
stack<int> w;
fordec(j,n,1){
while(w.size() && a[i][j]>a[i][w.top()]) w.pop();
if(i==2 && j==2){
//cerr<<a[i][j]<<" "<<a[i][w.top()];
//cerr<<w.top()<<"\n";
//gg
}
rt[i][j]=w.size() ? w.top() : 0;
while(w.size() && a[i][j]==a[i][w.top()]) w.pop();
w.push(j);
}
while(w.size()) w.pop();
forinc(j,1,n){
while(w.size() && a[i][j]>a[i][w.top()]) w.pop();
lf[i][j]=w.size() ? w.top() : 0;
while(w.size() && a[i][j]==a[i][w.top()]) w.pop();
w.push(j);
}
}
forinc(j,1,n){
stack<int> w;
fordec(i,m,1){
while(w.size() && a[i][j]>=a[w.top()][j]) w.pop();
dw[i][j]=w.size() ? w.top() : 0;
w.push(i);
}
}
forinc(i,1,m){
forinc(j,1,n){
//cout<<rt[i][j]<<" ";
}
//cout<<"\n";
}
if(m==3){
int tot=0;
forinc(i,2,n-1) if(a[2][i]<a[1][i] && a[2][i]<a[3][i]){
int j=i;
while(j<n && a[2][j]<a[1][j] && a[2][j]<a[3][j]){
if(i==4){
//cerr<<lf[2][j+1];
//gg/
}
tot+=rt[2][i-1]==j+1 || lf[2][j+1]==i-1;
if(rt[2][i-1]==j+1 || lf[2][j+1]==i-1){
//cerr<<i<<" "<<j<<"\n";
//cerr<<rt[2][i-1];
//gg
}
j++;
}
}
return tot;
}
}
#ifdef UNX
main(){
#define task "TASK"
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
int m,n; cin>>m>>n;
vector<vector<int>> a(m,vector<int>(n));
forv(i,a) forv(j,i) cin>>j;
cout<<count_rectangles(a);
}
#endif // UNX
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:88:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |