Submission #1031017

# Submission time Handle Problem Language Result Execution time Memory
1031017 2024-07-22T13:31:36 Z fv3 Rectangles (IOI19_rect) C++14
37 / 100
5000 ms 184764 KB
#include "rect.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N, M;
vector<vector<int>> grid;

struct node
{
	int n = 0;
};
node merge(node a, node b)
{
	return {max(a.n, b.n)};
}
node emptyNode = {0};

vector<vector<node>> st_v, st_h;
int nt_v = 1, nt_h = 1;

node v_range(int l, int r, int k, int x, int y, int i)
{
	if (y < l || x > r) return emptyNode;
	if (x >= l && y <= r) return st_v[i][k];
	int c = (x + y) / 2;
	return merge(v_range(l, r, k*2, x, c, i), v_range(l, r, k*2|1, c+1, y, i));
}

node h_range(int l, int r, int k, int x, int y, int i)
{
	if (y < l || x > r) return emptyNode;
	if (x >= l && y <= r) return st_h[i][k];
	int c = (x + y) / 2;
	return merge(h_range(l, r, k*2, x, c, i), h_range(l, r, k*2|1, c+1, y, i));
}

ll count_rectangles(vector<vector<int>> a) 
{
	N = a.size();
	M = a[0].size();

	// Construct horizontal segment trees
	while (nt_h < M) nt_h <<= 1;
	for (int i = 0; i < N; i++)
	{
		st_h.push_back(vector<node>(2 * nt_h));
		for (int j = 0; j < M; j++)
			st_h[i][nt_h + j].n = a[i][j];

		for (int j = nt_h - 1; j >= 1; j--)
			st_h[i][j] = merge(st_h[i][j*2], st_h[i][j*2|1]); 
	}

	// Construct vertical segment trees
	while (nt_v < N) nt_v <<= 1;
	for (int i = 0; i < M; i++)
	{
		st_v.push_back(vector<node>(2 * nt_v));
		for (int j = 0; j < N; j++)
			st_v[i][nt_v + j].n = a[j][i];

		for (int j = nt_v - 1; j >= 1; j--)
			st_v[i][j] = merge(st_v[i][j*2], st_v[i][j*2|1]);
	}

	set<ll> sv, sh;

	for (int x1 = 1; x1 < M - 1; x1++)
	{
		for (int x2 = x1; x2 < M - 1; x2++)
		{
			for (int y1 = 1; y1 < N - 1; y1++)
			{
				for (int y2 = y1; y2 < N - 1; y2++)
				{
					if (h_range(x1, x2, 1, 0, nt_h - 1, y2).n >= min(a[y2][x1-1], a[y2][x2+1])) 
						break;

					sh.insert(x1*15625000000ll+x2*6250000ll+y1*2500+y2);
				}
			}
		}
	}

	ll res = 0;
	for (int y1 = 1; y1 < N - 1; y1++)
	{
		for (int y2 = y1; y2 < N - 1; y2++)
		{
			for (int x1 = 1; x1 < M - 1; x1++)
			{
				for (int x2 = x1; x2 < M - 1; x2++)
				{
					if (v_range(y1, y2, 1, 0, nt_v - 1, x2).n >= min(a[y1-1][x2], a[y2+1][x2])) 
						break;

					if (sh.count(x1*15625000000ll+x2*6250000ll+y1*2500+y2))
					{
						res++;
					}
				}
			}
		}
	}

	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 928 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 928 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 96 ms 11904 KB Output is correct
23 Correct 94 ms 11836 KB Output is correct
24 Correct 92 ms 11856 KB Output is correct
25 Correct 19 ms 604 KB Output is correct
26 Correct 19 ms 964 KB Output is correct
27 Correct 20 ms 860 KB Output is correct
28 Correct 21 ms 1172 KB Output is correct
29 Correct 8 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 928 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 96 ms 11904 KB Output is correct
18 Correct 94 ms 11836 KB Output is correct
19 Correct 92 ms 11856 KB Output is correct
20 Correct 19 ms 604 KB Output is correct
21 Correct 19 ms 964 KB Output is correct
22 Correct 20 ms 860 KB Output is correct
23 Correct 21 ms 1172 KB Output is correct
24 Correct 8 ms 604 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1932 ms 184708 KB Output is correct
31 Correct 1954 ms 184764 KB Output is correct
32 Correct 1941 ms 184760 KB Output is correct
33 Correct 374 ms 2132 KB Output is correct
34 Correct 425 ms 3668 KB Output is correct
35 Correct 427 ms 3532 KB Output is correct
36 Correct 465 ms 9540 KB Output is correct
37 Correct 408 ms 7768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 928 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 96 ms 11904 KB Output is correct
18 Correct 94 ms 11836 KB Output is correct
19 Correct 92 ms 11856 KB Output is correct
20 Correct 19 ms 604 KB Output is correct
21 Correct 19 ms 964 KB Output is correct
22 Correct 20 ms 860 KB Output is correct
23 Correct 21 ms 1172 KB Output is correct
24 Correct 8 ms 604 KB Output is correct
25 Correct 1932 ms 184708 KB Output is correct
26 Correct 1954 ms 184764 KB Output is correct
27 Correct 1941 ms 184760 KB Output is correct
28 Correct 374 ms 2132 KB Output is correct
29 Correct 425 ms 3668 KB Output is correct
30 Correct 427 ms 3532 KB Output is correct
31 Correct 465 ms 9540 KB Output is correct
32 Correct 408 ms 7768 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Execution timed out 5044 ms 19028 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 325 ms 852 KB Output is correct
2 Correct 280 ms 748 KB Output is correct
3 Correct 330 ms 768 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 321 ms 772 KB Output is correct
6 Correct 290 ms 788 KB Output is correct
7 Correct 297 ms 788 KB Output is correct
8 Correct 285 ms 840 KB Output is correct
9 Correct 295 ms 784 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Execution timed out 5097 ms 100004 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 928 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 96 ms 11904 KB Output is correct
18 Correct 94 ms 11836 KB Output is correct
19 Correct 92 ms 11856 KB Output is correct
20 Correct 19 ms 604 KB Output is correct
21 Correct 19 ms 964 KB Output is correct
22 Correct 20 ms 860 KB Output is correct
23 Correct 21 ms 1172 KB Output is correct
24 Correct 8 ms 604 KB Output is correct
25 Correct 1932 ms 184708 KB Output is correct
26 Correct 1954 ms 184764 KB Output is correct
27 Correct 1941 ms 184760 KB Output is correct
28 Correct 374 ms 2132 KB Output is correct
29 Correct 425 ms 3668 KB Output is correct
30 Correct 427 ms 3532 KB Output is correct
31 Correct 465 ms 9540 KB Output is correct
32 Correct 408 ms 7768 KB Output is correct
33 Execution timed out 5044 ms 19028 KB Time limit exceeded
34 Halted 0 ms 0 KB -