Submission #144082

# Submission time Handle Problem Language Result Execution time Memory
144082 2019-08-16T01:51:22 Z Lyestria Rectangles (IOI19_rect) C++14
72 / 100
5000 ms 432732 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];
    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]);
    }
    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];
set<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 2428 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1656 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 1016 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 4 ms 2424 KB Output is correct
20 Correct 4 ms 2040 KB Output is correct
21 Correct 3 ms 888 KB Output is correct
# 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 2428 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1656 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 1016 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 11 ms 6392 KB Output is correct
18 Correct 10 ms 6392 KB Output is correct
19 Correct 10 ms 6392 KB Output is correct
20 Correct 9 ms 6136 KB Output is correct
21 Correct 9 ms 6136 KB Output is correct
22 Correct 9 ms 6136 KB Output is correct
23 Correct 9 ms 6136 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 4 ms 2424 KB Output is correct
28 Correct 4 ms 2040 KB Output is correct
29 Correct 3 ms 888 KB Output is correct
# 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 2428 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1656 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 1016 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 11 ms 6392 KB Output is correct
18 Correct 10 ms 6392 KB Output is correct
19 Correct 10 ms 6392 KB Output is correct
20 Correct 9 ms 6136 KB Output is correct
21 Correct 9 ms 6136 KB Output is correct
22 Correct 9 ms 6136 KB Output is correct
23 Correct 9 ms 6136 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 46 ms 17528 KB Output is correct
26 Correct 46 ms 17528 KB Output is correct
27 Correct 46 ms 17592 KB Output is correct
28 Correct 34 ms 15992 KB Output is correct
29 Correct 37 ms 16376 KB Output is correct
30 Correct 38 ms 16376 KB Output is correct
31 Correct 40 ms 16376 KB Output is correct
32 Correct 38 ms 16248 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 4 ms 2424 KB Output is correct
36 Correct 4 ms 2040 KB Output is correct
37 Correct 3 ms 888 KB Output is correct
# 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 2428 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1656 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 1016 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 11 ms 6392 KB Output is correct
18 Correct 10 ms 6392 KB Output is correct
19 Correct 10 ms 6392 KB Output is correct
20 Correct 9 ms 6136 KB Output is correct
21 Correct 9 ms 6136 KB Output is correct
22 Correct 9 ms 6136 KB Output is correct
23 Correct 9 ms 6136 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 46 ms 17528 KB Output is correct
26 Correct 46 ms 17528 KB Output is correct
27 Correct 46 ms 17592 KB Output is correct
28 Correct 34 ms 15992 KB Output is correct
29 Correct 37 ms 16376 KB Output is correct
30 Correct 38 ms 16376 KB Output is correct
31 Correct 40 ms 16376 KB Output is correct
32 Correct 38 ms 16248 KB Output is correct
33 Correct 311 ms 69512 KB Output is correct
34 Correct 313 ms 69496 KB Output is correct
35 Correct 324 ms 69528 KB Output is correct
36 Correct 317 ms 69680 KB Output is correct
37 Correct 596 ms 92564 KB Output is correct
38 Correct 621 ms 92408 KB Output is correct
39 Correct 630 ms 92408 KB Output is correct
40 Correct 577 ms 87672 KB Output is correct
41 Correct 349 ms 70524 KB Output is correct
42 Correct 364 ms 71744 KB Output is correct
43 Correct 432 ms 77264 KB Output is correct
44 Correct 417 ms 77376 KB Output is correct
45 Correct 216 ms 53880 KB Output is correct
46 Correct 213 ms 48144 KB Output is correct
47 Correct 479 ms 77276 KB Output is correct
48 Correct 442 ms 77460 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 3 ms 504 KB Output is correct
51 Correct 4 ms 2424 KB Output is correct
52 Correct 4 ms 2040 KB Output is correct
53 Correct 3 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 65528 KB Output is correct
2 Correct 56 ms 55800 KB Output is correct
3 Correct 56 ms 65400 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 55 ms 65408 KB Output is correct
6 Correct 55 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 54 ms 65528 KB Output is correct
10 Correct 51 ms 65144 KB Output is correct
11 Correct 53 ms 65272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1020 KB Output is correct
2 Correct 1987 ms 212012 KB Output is correct
3 Correct 4291 ms 354920 KB Output is correct
4 Correct 4347 ms 356044 KB Output is correct
5 Correct 4289 ms 356216 KB Output is correct
6 Correct 1866 ms 215068 KB Output is correct
7 Correct 3580 ms 335220 KB Output is correct
8 Correct 3971 ms 344420 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2040 KB Output is correct
13 Correct 3 ms 888 KB Output is correct
# 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 2428 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1656 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 1016 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 11 ms 6392 KB Output is correct
18 Correct 10 ms 6392 KB Output is correct
19 Correct 10 ms 6392 KB Output is correct
20 Correct 9 ms 6136 KB Output is correct
21 Correct 9 ms 6136 KB Output is correct
22 Correct 9 ms 6136 KB Output is correct
23 Correct 9 ms 6136 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 46 ms 17528 KB Output is correct
26 Correct 46 ms 17528 KB Output is correct
27 Correct 46 ms 17592 KB Output is correct
28 Correct 34 ms 15992 KB Output is correct
29 Correct 37 ms 16376 KB Output is correct
30 Correct 38 ms 16376 KB Output is correct
31 Correct 40 ms 16376 KB Output is correct
32 Correct 38 ms 16248 KB Output is correct
33 Correct 311 ms 69512 KB Output is correct
34 Correct 313 ms 69496 KB Output is correct
35 Correct 324 ms 69528 KB Output is correct
36 Correct 317 ms 69680 KB Output is correct
37 Correct 596 ms 92564 KB Output is correct
38 Correct 621 ms 92408 KB Output is correct
39 Correct 630 ms 92408 KB Output is correct
40 Correct 577 ms 87672 KB Output is correct
41 Correct 349 ms 70524 KB Output is correct
42 Correct 364 ms 71744 KB Output is correct
43 Correct 432 ms 77264 KB Output is correct
44 Correct 417 ms 77376 KB Output is correct
45 Correct 216 ms 53880 KB Output is correct
46 Correct 213 ms 48144 KB Output is correct
47 Correct 479 ms 77276 KB Output is correct
48 Correct 442 ms 77460 KB Output is correct
49 Correct 55 ms 65528 KB Output is correct
50 Correct 56 ms 55800 KB Output is correct
51 Correct 56 ms 65400 KB Output is correct
52 Correct 2 ms 504 KB Output is correct
53 Correct 55 ms 65408 KB Output is correct
54 Correct 55 ms 65528 KB Output is correct
55 Correct 55 ms 65528 KB Output is correct
56 Correct 54 ms 65528 KB Output is correct
57 Correct 54 ms 65528 KB Output is correct
58 Correct 51 ms 65144 KB Output is correct
59 Correct 53 ms 65272 KB Output is correct
60 Correct 3 ms 1020 KB Output is correct
61 Correct 1987 ms 212012 KB Output is correct
62 Correct 4291 ms 354920 KB Output is correct
63 Correct 4347 ms 356044 KB Output is correct
64 Correct 4289 ms 356216 KB Output is correct
65 Correct 1866 ms 215068 KB Output is correct
66 Correct 3580 ms 335220 KB Output is correct
67 Correct 3971 ms 344420 KB Output is correct
68 Correct 3833 ms 344308 KB Output is correct
69 Correct 3841 ms 344292 KB Output is correct
70 Correct 3838 ms 344368 KB Output is correct
71 Correct 3933 ms 344264 KB Output is correct
72 Execution timed out 5105 ms 432732 KB Time limit exceeded
73 Halted 0 ms 0 KB -