Submission #836457

# Submission time Handle Problem Language Result Execution time Memory
836457 2023-08-24T11:26:48 Z Rafi22 Rectangles (IOI19_rect) C++14
27 / 100
5000 ms 429776 KB
#include <bits/stdc++.h>
     
using namespace std;
     
#define ll long long 
#define ld long double
#define pb push_back
#define st first
#define nd second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
int inf=1000000007;
ll infl=1000000000000000007;

const int N=2007,pot=1<<11;

set<int>V[N][N];
int U[N][2*pot+7];
int D[N][2*pot+7];
int n,m;

int queU(int v,int a,int b,int l,int r,int i)
{
	if(a<=l&&b>=r) return U[i][v];
	if(r<a||l>b) return -1;
	return max(queU(2*v,a,b,l,(l+r)/2,i),queU(2*v+1,a,b,(l+r)/2+1,r,i));
}
int queD(int v,int a,int b,int l,int r,int i)
{
	if(a<=l&&b>=r) return D[i][v];
	if(r<a||l>b) return n;
	return min(queD(2*v,a,b,l,(l+r)/2,i),queD(2*v+1,a,b,(l+r)/2+1,r,i));
}
     
ll count_rectangles(vector<vector<int>>a)
{
	ll ans=0;
	n=sz(a),m=sz(a[0]);
	for(int i=1;i<n-1;i++)
	{
		deque<pair<int,int>>Q;
		Q.pb({a[i][0],0});
		for(int j=1;j<m;j++)
		{
			while(sz(Q)>0&&Q.back().st<a[i][j]) Q.pop_back();
			if(sz(Q)>0) V[Q.back().nd+1][j-1].insert(i);
			Q.pb({a[i][j],j});
		}
		Q.clear();
		Q.pb({a[i][m-1],m-1});
		for(int j=m-2;j>=0;j--)
		{
			while(sz(Q)>0&&Q.back().st<a[i][j]) Q.pop_back();
			if(sz(Q)>0) V[j+1][Q.back().nd-1].insert(i);
			Q.pb({a[i][j],j});
		}
	}
	for(int i=0;i<n;i++)
	{
		 for(int j=1;j<2*pot;j++) 
		 {
			 U[i][j]=-1;
			 D[i][j]=n;
		 }
	}
	for(int j=0;j<m;j++)
	{
		deque<pair<int,int>>Q;
		Q.pb({a[0][j],0});
		for(int i=1;i<n;i++)
		{
			while(sz(Q)>0&&Q.back().st<a[i][j]) Q.pop_back();
			if(sz(Q)>0) U[i][j+pot]=Q.back().nd;
			Q.pb({a[i][j],i});
		}
		Q.clear();
		Q.pb({a[n-1][j],n-1});
		for(int i=n-2;i>=0;i--)
		{
			while(sz(Q)>0&&Q.back().st<a[i][j]) Q.pop_back();
			if(sz(Q)>0) D[i][j+pot]=Q.back().nd;;
			Q.pb({a[i][j],i});
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=pot-1;j>0;j--)
		{
			U[i][j]=max(U[i][2*j],U[i][2*j+1]);
			D[i][j]=min(D[i][2*j],D[i][2*j+1]);
		}
	}
	for(int i=0;i<m;i++)
	{
		for(int j=i;j<m;j++)
		{
			//cout<<i<<" "<<j<<endl;
			int p=0,l=-1;
			for(auto x:V[i][j]) 
			{
				if(x!=l+1) p=x;
				l=x;
				for(int y=p;y<=x;y++) 
				{
				//	cout<<i<<" "<<j<<" "<<y<<" "<<x<<" "<<queD(1,i+1,j+1,1,pot,y-1)<<" "<<queU(1,i+1,j+1,1,pot,x+1)<<endl;
					if(queD(1,i+1,j+1,1,pot,y-1)>x&&queU(1,i+1,j+1,1,pot,x+1)<y)
					{
						//cout<<"TAK"<<endl;
						ans++;
					}
				}
				//cout<<"Xd "<<p<<" "<<x<<endl;
				//cout<<x<<endl;
			}
			//cout<<ans<<endl;
		}
	}
	return ans;
}
/*
int main()
{
	cout<<count_rectangles({
{4, 8, 7, 5, 6},
{7, 4, 10, 3, 5},
{9, 7, 20, 14, 2},
{9, 14, 7, 3, 6},
{5, 7, 5, 2, 7},
{4, 5, 13, 5, 6}})<<endl;
	return 0;
}*/
    

# Verdict Execution time Memory Grader output
1 Correct 79 ms 189720 KB Output is correct
2 Correct 79 ms 190464 KB Output is correct
3 Correct 80 ms 190492 KB Output is correct
4 Correct 90 ms 190508 KB Output is correct
5 Correct 75 ms 190404 KB Output is correct
6 Correct 77 ms 190488 KB Output is correct
7 Correct 76 ms 190408 KB Output is correct
8 Correct 79 ms 189792 KB Output is correct
9 Correct 77 ms 190508 KB Output is correct
10 Correct 75 ms 190516 KB Output is correct
11 Correct 83 ms 190432 KB Output is correct
12 Correct 83 ms 190480 KB Output is correct
13 Correct 81 ms 189508 KB Output is correct
14 Correct 88 ms 189772 KB Output is correct
15 Correct 75 ms 189680 KB Output is correct
16 Correct 75 ms 189468 KB Output is correct
17 Correct 75 ms 189492 KB Output is correct
18 Correct 83 ms 189424 KB Output is correct
19 Correct 83 ms 190432 KB Output is correct
20 Correct 77 ms 190440 KB Output is correct
21 Correct 77 ms 189684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 189720 KB Output is correct
2 Correct 79 ms 190464 KB Output is correct
3 Correct 80 ms 190492 KB Output is correct
4 Correct 90 ms 190508 KB Output is correct
5 Correct 75 ms 190404 KB Output is correct
6 Correct 77 ms 190488 KB Output is correct
7 Correct 76 ms 190408 KB Output is correct
8 Correct 79 ms 189792 KB Output is correct
9 Correct 77 ms 190508 KB Output is correct
10 Correct 75 ms 190516 KB Output is correct
11 Correct 83 ms 190432 KB Output is correct
12 Correct 83 ms 190480 KB Output is correct
13 Correct 81 ms 189508 KB Output is correct
14 Correct 88 ms 189772 KB Output is correct
15 Correct 75 ms 189680 KB Output is correct
16 Correct 75 ms 189468 KB Output is correct
17 Correct 75 ms 189492 KB Output is correct
18 Correct 83 ms 189424 KB Output is correct
19 Correct 83 ms 190432 KB Output is correct
20 Correct 77 ms 190440 KB Output is correct
21 Correct 77 ms 189684 KB Output is correct
22 Correct 121 ms 192664 KB Output is correct
23 Correct 120 ms 192572 KB Output is correct
24 Correct 121 ms 192676 KB Output is correct
25 Correct 80 ms 192484 KB Output is correct
26 Correct 81 ms 192588 KB Output is correct
27 Correct 85 ms 192564 KB Output is correct
28 Correct 82 ms 192516 KB Output is correct
29 Correct 86 ms 192332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 189720 KB Output is correct
2 Correct 79 ms 190464 KB Output is correct
3 Correct 80 ms 190492 KB Output is correct
4 Correct 90 ms 190508 KB Output is correct
5 Correct 75 ms 190404 KB Output is correct
6 Correct 77 ms 190488 KB Output is correct
7 Correct 76 ms 190408 KB Output is correct
8 Correct 79 ms 189792 KB Output is correct
9 Correct 77 ms 190508 KB Output is correct
10 Correct 75 ms 190516 KB Output is correct
11 Correct 83 ms 190432 KB Output is correct
12 Correct 83 ms 190480 KB Output is correct
13 Correct 81 ms 189508 KB Output is correct
14 Correct 88 ms 189772 KB Output is correct
15 Correct 75 ms 189680 KB Output is correct
16 Correct 75 ms 189468 KB Output is correct
17 Correct 121 ms 192664 KB Output is correct
18 Correct 120 ms 192572 KB Output is correct
19 Correct 121 ms 192676 KB Output is correct
20 Correct 80 ms 192484 KB Output is correct
21 Correct 81 ms 192588 KB Output is correct
22 Correct 85 ms 192564 KB Output is correct
23 Correct 82 ms 192516 KB Output is correct
24 Correct 86 ms 192332 KB Output is correct
25 Correct 75 ms 189492 KB Output is correct
26 Correct 83 ms 189424 KB Output is correct
27 Correct 83 ms 190432 KB Output is correct
28 Correct 77 ms 190440 KB Output is correct
29 Correct 77 ms 189684 KB Output is correct
30 Correct 830 ms 199924 KB Output is correct
31 Correct 889 ms 199916 KB Output is correct
32 Correct 836 ms 199916 KB Output is correct
33 Correct 93 ms 198792 KB Output is correct
34 Correct 101 ms 199732 KB Output is correct
35 Correct 113 ms 199732 KB Output is correct
36 Correct 112 ms 199624 KB Output is correct
37 Correct 112 ms 199632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 189720 KB Output is correct
2 Correct 79 ms 190464 KB Output is correct
3 Correct 80 ms 190492 KB Output is correct
4 Correct 90 ms 190508 KB Output is correct
5 Correct 75 ms 190404 KB Output is correct
6 Correct 77 ms 190488 KB Output is correct
7 Correct 76 ms 190408 KB Output is correct
8 Correct 79 ms 189792 KB Output is correct
9 Correct 77 ms 190508 KB Output is correct
10 Correct 75 ms 190516 KB Output is correct
11 Correct 83 ms 190432 KB Output is correct
12 Correct 83 ms 190480 KB Output is correct
13 Correct 81 ms 189508 KB Output is correct
14 Correct 88 ms 189772 KB Output is correct
15 Correct 75 ms 189680 KB Output is correct
16 Correct 75 ms 189468 KB Output is correct
17 Correct 121 ms 192664 KB Output is correct
18 Correct 120 ms 192572 KB Output is correct
19 Correct 121 ms 192676 KB Output is correct
20 Correct 80 ms 192484 KB Output is correct
21 Correct 81 ms 192588 KB Output is correct
22 Correct 85 ms 192564 KB Output is correct
23 Correct 82 ms 192516 KB Output is correct
24 Correct 86 ms 192332 KB Output is correct
25 Correct 830 ms 199924 KB Output is correct
26 Correct 889 ms 199916 KB Output is correct
27 Correct 836 ms 199916 KB Output is correct
28 Correct 93 ms 198792 KB Output is correct
29 Correct 101 ms 199732 KB Output is correct
30 Correct 113 ms 199732 KB Output is correct
31 Correct 112 ms 199624 KB Output is correct
32 Correct 112 ms 199632 KB Output is correct
33 Correct 75 ms 189492 KB Output is correct
34 Correct 83 ms 189424 KB Output is correct
35 Correct 83 ms 190432 KB Output is correct
36 Correct 77 ms 190440 KB Output is correct
37 Correct 77 ms 189684 KB Output is correct
38 Correct 256 ms 250228 KB Output is correct
39 Correct 229 ms 250168 KB Output is correct
40 Correct 327 ms 250120 KB Output is correct
41 Correct 253 ms 250164 KB Output is correct
42 Execution timed out 5067 ms 261568 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 225 ms 384356 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 189492 KB Output is correct
2 Correct 83 ms 189424 KB Output is correct
3 Correct 83 ms 190432 KB Output is correct
4 Correct 77 ms 190440 KB Output is correct
5 Correct 77 ms 189684 KB Output is correct
6 Correct 78 ms 189688 KB Output is correct
7 Runtime error 271 ms 429776 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 79 ms 189720 KB Output is correct
2 Correct 79 ms 190464 KB Output is correct
3 Correct 80 ms 190492 KB Output is correct
4 Correct 90 ms 190508 KB Output is correct
5 Correct 75 ms 190404 KB Output is correct
6 Correct 77 ms 190488 KB Output is correct
7 Correct 76 ms 190408 KB Output is correct
8 Correct 79 ms 189792 KB Output is correct
9 Correct 77 ms 190508 KB Output is correct
10 Correct 75 ms 190516 KB Output is correct
11 Correct 83 ms 190432 KB Output is correct
12 Correct 83 ms 190480 KB Output is correct
13 Correct 81 ms 189508 KB Output is correct
14 Correct 88 ms 189772 KB Output is correct
15 Correct 75 ms 189680 KB Output is correct
16 Correct 75 ms 189468 KB Output is correct
17 Correct 121 ms 192664 KB Output is correct
18 Correct 120 ms 192572 KB Output is correct
19 Correct 121 ms 192676 KB Output is correct
20 Correct 80 ms 192484 KB Output is correct
21 Correct 81 ms 192588 KB Output is correct
22 Correct 85 ms 192564 KB Output is correct
23 Correct 82 ms 192516 KB Output is correct
24 Correct 86 ms 192332 KB Output is correct
25 Correct 830 ms 199924 KB Output is correct
26 Correct 889 ms 199916 KB Output is correct
27 Correct 836 ms 199916 KB Output is correct
28 Correct 93 ms 198792 KB Output is correct
29 Correct 101 ms 199732 KB Output is correct
30 Correct 113 ms 199732 KB Output is correct
31 Correct 112 ms 199624 KB Output is correct
32 Correct 112 ms 199632 KB Output is correct
33 Correct 256 ms 250228 KB Output is correct
34 Correct 229 ms 250168 KB Output is correct
35 Correct 327 ms 250120 KB Output is correct
36 Correct 253 ms 250164 KB Output is correct
37 Execution timed out 5067 ms 261568 KB Time limit exceeded
38 Halted 0 ms 0 KB -