# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
144085 |
2019-08-16T01:58:36 Z |
Lyestria |
Rectangles (IOI19_rect) |
C++14 |
|
2027 ms |
213540 KB |
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=2510;
struct seg{
int seg[mn*2];
inline void up(int a,int b){
seg[a+=mn]=b;
for(a>>=1;a;a>>=1)seg[a]=min(seg[a<<1],seg[(a<<1)^1]);
}
inline int qu(int a,int b){
int ans=0x3f3f3f3f;
for(a+=mn,b+=mn;a<=b;a>>=1,b>>=1){
if(a&1)ans=min(ans,seg[a++]);
if(!(b&1))ans=min(ans,seg[b--]);
}
return ans;
}
};
seg lef[mn],rig[mn],up[mn],dow[mn];
int elef[mn][mn],erig[mn][mn],eup[mn][mn],edow[mn][mn];
multiset<ll>ss;
long long hsh(ll a,ll b,ll c,ll d){
return (a<<48)|(b<<32)|(c<<16)|d;
}
long long count_rectangles(std::vector<std::vector<int> > a) {
int n=a.size(),m=a[0].size();
int i,j;
for(i=0;i<n;i++){
stack<int>s;
for(j=0;j<m;j++){
while(s.size()&&a[i][s.top()]<=a[i][j])rig[s.top()].up(i,j),s.pop();
s.push(j);
}
while(s.size())rig[s.top()].up(i,j),s.pop();
for(j=m-1;j>=0;j--){
while(s.size()&&a[i][s.top()]<=a[i][j])lef[s.top()].up(i,-j),s.pop();
s.push(j);
}
while(s.size())lef[s.top()].up(i,-j),s.pop();
for(j=0;j<m;j++){
while(s.size()&&a[i][s.top()]<a[i][j])erig[i][s.top()]=j,s.pop();
s.push(j);
}
while(s.size())erig[i][s.top()]=j,s.pop();
for(j=m-1;j>=0;j--){
while(s.size()&&a[i][s.top()]<a[i][j])elef[i][s.top()]=j,s.pop();
s.push(j);
}
while(s.size())elef[i][s.top()]=j,s.pop();
}
for(i=0;i<m;i++){
stack<int>s;
for(j=0;j<n;j++){
while(s.size()&&a[s.top()][i]<=a[j][i])dow[s.top()].up(i,j),s.pop();
s.push(j);
}
while(s.size())dow[s.top()].up(i,j),s.pop();
for(j=n-1;j>=0;j--){
while(s.size()&&a[s.top()][i]<=a[j][i])up[s.top()].up(i,-j),s.pop();
s.push(j);
}
while(s.size())up[s.top()].up(i,-j),s.pop();
for(j=0;j<n;j++){
while(s.size()&&a[s.top()][i]<a[j][i])edow[s.top()][i]=j,s.pop();
s.push(j);
}
while(s.size())edow[s.top()][i]=j,s.pop();
for(j=n-1;j>=0;j--){
while(s.size()&&a[s.top()][i]<a[j][i])eup[s.top()][i]=j,s.pop();
s.push(j);
}
while(s.size())eup[s.top()][i]=j,s.pop();
}
int ans=0;
for(i=1;i<n-1;i++){
for(j=1;j<m-1;j++){
int d,u,l,r;
d=edow[i][j];
u=eup[i][j];
l=elef[i][j];
r=erig[i][j];
if(l==-1||u==-1||r==m||d==n)continue;
if(rig[l].qu(u+1,d-1)<r)continue;
if(-lef[r].qu(u+1,d-1)>l)continue;
if(dow[u].qu(l+1,r-1)<d)continue;
if(-up[d].qu(l+1,r-1)>u)continue;
ss.insert(hsh(d,u,l,r));
}
}
return ss.size();
}
Compilation message
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:76:6: warning: unused variable 'ans' [-Wunused-variable]
int ans=0;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2552 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2552 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2552 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2552 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
65608 KB |
Output is correct |
2 |
Correct |
47 ms |
55740 KB |
Output is correct |
3 |
Correct |
54 ms |
65528 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
70 ms |
65556 KB |
Output is correct |
6 |
Correct |
54 ms |
65528 KB |
Output is correct |
7 |
Correct |
55 ms |
65528 KB |
Output is correct |
8 |
Correct |
54 ms |
65528 KB |
Output is correct |
9 |
Correct |
58 ms |
65400 KB |
Output is correct |
10 |
Correct |
54 ms |
65144 KB |
Output is correct |
11 |
Correct |
63 ms |
65276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Incorrect |
2027 ms |
213540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Correct |
4 ms |
2552 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |