Submission #1047480

# Submission time Handle Problem Language Result Execution time Memory
1047480 2024-08-07T13:31:25 Z fuad27 Rectangles (IOI19_rect) C++17
72 / 100
5000 ms 752168 KB
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int N = 2510;
int n,m;
vector<pair<int,int>> gdr[N];
vector<pair<int,int>> gdc[N];

struct Side {
	int r1, r2, c1, c2;
};
vector<pair<int,int>> hsides[N][N];
vector<pair<int,int>> vsides[N][N];
vector<pair<int,int>> swp[N];
long long count_rectangles(std::vector<std::vector<int> > a) {
	n = a.size();
	m = a[0].size();
	for(int i = 0;i<n;i++) {
		vector<int> stk;
		for(int j = 0;j<m;j++) {
			while(stk.size() and a[i][stk.back()] < a[i][j]){
				stk.pop_back();
			}
			if(stk.size()) {
				gdr[i].push_back({stk.back(), j});
			}
			stk.push_back(j);
		}
		stk.clear();
		for(int j = m-1;j>=0;j--) {
			while(stk.size() and a[i][stk.back()] < a[i][j])stk.pop_back();
			if(stk.size()) {
				if(a[i][j] != a[i][stk.back()])
					gdr[i].push_back({j, stk.back()});
			}
			stk.push_back(j);
		}
		sort(gdr[i].begin(), gdr[i].end());
	}
	for(int i = 0;i<m;i++) {
		vector<int> stk;
		for(int j = 0;j<n;j++) {
			while(stk.size() and a[stk.back()][i] < a[j][i]){
				stk.pop_back();
			}
			if(stk.size()) {
				gdc[i].push_back({stk.back(), j});
			}
			stk.push_back(j);
		}
		stk.clear();
		for(int j = n-1;j>=0;j--) {
			while(stk.size() and a[stk.back()][i] < a[j][i])stk.pop_back();
			if(stk.size()) {
				gdc[i].push_back({j, stk.back()});
			}
			stk.push_back(j);
		}
		sort(gdc[i].begin(), gdc[i].end());
		gdc[i].erase(unique(gdc[i].begin(), gdc[i].end()), gdc[i].end());
	}
	Side seg;
	for(int i = 0;i<n;i++) {
		for(auto pr:gdr[i]) {

			if(pr.first +1 == pr.second)continue;
			if(i!=n-1 and (*lower_bound(gdr[i+1].begin(), gdr[i+1].end(), pr)) == pr)continue;
			seg.r1 = pr.first;
			seg.r2 = pr.second;
			seg.c2 = i;
			for(int j = i;j>=0;j--){
				auto it = (lower_bound(gdr[j].begin(), gdr[j].end(), pr));
				if(it == gdr[j].end())break;
				if((*it)!=pr)break;
				seg.c1=j;
			}
			seg.c1--;
			seg.c2++;
			seg.c1=max(seg.c1, 0);
			seg.c2=min(seg.c2, n-1);
			for(int j = seg.c1;j<=seg.c2;j++) {
				hsides[j][seg.r2].push_back(pair<int,int>(seg.c1, seg.r1));
			}
		}
	}
	for(int i = 0;i<m;i++) {
		for(auto pr:gdc[i]) {
			if(pr.first +1 == pr.second)continue;
			if(i!=m-1 and (*lower_bound(gdc[i+1].begin(), gdc[i+1].end(), pr)) == pr)continue;
			seg.r1 = pr.first;
			seg.r2 = pr.second;
			seg.c2 = i;
			for(int j = i;j>=0;j--){
				auto it = (lower_bound(gdc[j].begin(), gdc[j].end(), pr));
				if(it == gdc[j].end())break;
				if((*it)!=pr)break;
				seg.c1=j;
			}
			seg.c1--;
			seg.c2++;
			seg.c1=max(seg.c1, 0);
			seg.c2=min(seg.c2, m-1);
			for(int j = seg.c1;j<=seg.c2;j++) {
				vsides[seg.r2][j].push_back(pair<int,int>(seg.c1, seg.r1));
			}
		}
	}


	long long ans=0;
	for(int i = 0;i<n;i++) {
		for(int j = 0;j<m;j++) {
			int tmp=0;
			for(auto k:vsides[i][j]) {
				for(auto k2:hsides[i][j]) {
					if(k2.second >= k.first and k2.first <= k.second) {
//						cout << i << " " << k2.r1 << " " <<  k.r1 << " " << j <<  endl;
						ans++;
						tmp++;
					}

				}
			}
//			cout << i << " " << j << " " << tmp << endl;
		}
	}
	return ans;
}

Compilation message

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:100:10: warning: 'seg.Side::c1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  100 |    seg.c1--;
      |    ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 56 ms 296248 KB Output is correct
2 Correct 56 ms 296532 KB Output is correct
3 Correct 58 ms 296524 KB Output is correct
4 Correct 78 ms 296352 KB Output is correct
5 Correct 56 ms 296528 KB Output is correct
6 Correct 56 ms 296536 KB Output is correct
7 Correct 56 ms 296532 KB Output is correct
8 Correct 56 ms 296276 KB Output is correct
9 Correct 61 ms 296528 KB Output is correct
10 Correct 55 ms 296528 KB Output is correct
11 Correct 55 ms 296532 KB Output is correct
12 Correct 53 ms 296532 KB Output is correct
13 Correct 72 ms 296380 KB Output is correct
14 Correct 43 ms 296252 KB Output is correct
15 Correct 55 ms 296304 KB Output is correct
16 Correct 55 ms 296280 KB Output is correct
17 Correct 72 ms 296280 KB Output is correct
18 Correct 75 ms 296336 KB Output is correct
19 Correct 56 ms 296420 KB Output is correct
20 Correct 76 ms 296480 KB Output is correct
21 Correct 70 ms 296412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 296248 KB Output is correct
2 Correct 56 ms 296532 KB Output is correct
3 Correct 58 ms 296524 KB Output is correct
4 Correct 78 ms 296352 KB Output is correct
5 Correct 56 ms 296528 KB Output is correct
6 Correct 56 ms 296536 KB Output is correct
7 Correct 56 ms 296532 KB Output is correct
8 Correct 56 ms 296276 KB Output is correct
9 Correct 61 ms 296528 KB Output is correct
10 Correct 55 ms 296528 KB Output is correct
11 Correct 55 ms 296532 KB Output is correct
12 Correct 53 ms 296532 KB Output is correct
13 Correct 72 ms 296380 KB Output is correct
14 Correct 43 ms 296252 KB Output is correct
15 Correct 55 ms 296304 KB Output is correct
16 Correct 55 ms 296280 KB Output is correct
17 Correct 72 ms 296280 KB Output is correct
18 Correct 75 ms 296336 KB Output is correct
19 Correct 56 ms 296420 KB Output is correct
20 Correct 76 ms 296480 KB Output is correct
21 Correct 70 ms 296412 KB Output is correct
22 Correct 63 ms 296784 KB Output is correct
23 Correct 54 ms 296884 KB Output is correct
24 Correct 53 ms 297048 KB Output is correct
25 Correct 61 ms 297044 KB Output is correct
26 Correct 59 ms 297304 KB Output is correct
27 Correct 59 ms 297300 KB Output is correct
28 Correct 54 ms 297196 KB Output is correct
29 Correct 73 ms 296728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 296248 KB Output is correct
2 Correct 56 ms 296532 KB Output is correct
3 Correct 58 ms 296524 KB Output is correct
4 Correct 78 ms 296352 KB Output is correct
5 Correct 56 ms 296528 KB Output is correct
6 Correct 56 ms 296536 KB Output is correct
7 Correct 56 ms 296532 KB Output is correct
8 Correct 56 ms 296276 KB Output is correct
9 Correct 61 ms 296528 KB Output is correct
10 Correct 55 ms 296528 KB Output is correct
11 Correct 55 ms 296532 KB Output is correct
12 Correct 53 ms 296532 KB Output is correct
13 Correct 72 ms 296380 KB Output is correct
14 Correct 43 ms 296252 KB Output is correct
15 Correct 55 ms 296304 KB Output is correct
16 Correct 55 ms 296280 KB Output is correct
17 Correct 63 ms 296784 KB Output is correct
18 Correct 54 ms 296884 KB Output is correct
19 Correct 53 ms 297048 KB Output is correct
20 Correct 61 ms 297044 KB Output is correct
21 Correct 59 ms 297304 KB Output is correct
22 Correct 59 ms 297300 KB Output is correct
23 Correct 54 ms 297196 KB Output is correct
24 Correct 73 ms 296728 KB Output is correct
25 Correct 72 ms 296280 KB Output is correct
26 Correct 75 ms 296336 KB Output is correct
27 Correct 56 ms 296420 KB Output is correct
28 Correct 76 ms 296480 KB Output is correct
29 Correct 70 ms 296412 KB Output is correct
30 Correct 57 ms 299088 KB Output is correct
31 Correct 51 ms 299028 KB Output is correct
32 Correct 73 ms 299092 KB Output is correct
33 Correct 72 ms 300112 KB Output is correct
34 Correct 82 ms 301392 KB Output is correct
35 Correct 83 ms 301520 KB Output is correct
36 Correct 80 ms 301056 KB Output is correct
37 Correct 81 ms 300928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 296248 KB Output is correct
2 Correct 56 ms 296532 KB Output is correct
3 Correct 58 ms 296524 KB Output is correct
4 Correct 78 ms 296352 KB Output is correct
5 Correct 56 ms 296528 KB Output is correct
6 Correct 56 ms 296536 KB Output is correct
7 Correct 56 ms 296532 KB Output is correct
8 Correct 56 ms 296276 KB Output is correct
9 Correct 61 ms 296528 KB Output is correct
10 Correct 55 ms 296528 KB Output is correct
11 Correct 55 ms 296532 KB Output is correct
12 Correct 53 ms 296532 KB Output is correct
13 Correct 72 ms 296380 KB Output is correct
14 Correct 43 ms 296252 KB Output is correct
15 Correct 55 ms 296304 KB Output is correct
16 Correct 55 ms 296280 KB Output is correct
17 Correct 63 ms 296784 KB Output is correct
18 Correct 54 ms 296884 KB Output is correct
19 Correct 53 ms 297048 KB Output is correct
20 Correct 61 ms 297044 KB Output is correct
21 Correct 59 ms 297304 KB Output is correct
22 Correct 59 ms 297300 KB Output is correct
23 Correct 54 ms 297196 KB Output is correct
24 Correct 73 ms 296728 KB Output is correct
25 Correct 57 ms 299088 KB Output is correct
26 Correct 51 ms 299028 KB Output is correct
27 Correct 73 ms 299092 KB Output is correct
28 Correct 72 ms 300112 KB Output is correct
29 Correct 82 ms 301392 KB Output is correct
30 Correct 83 ms 301520 KB Output is correct
31 Correct 80 ms 301056 KB Output is correct
32 Correct 81 ms 300928 KB Output is correct
33 Correct 72 ms 296280 KB Output is correct
34 Correct 75 ms 296336 KB Output is correct
35 Correct 56 ms 296420 KB Output is correct
36 Correct 76 ms 296480 KB Output is correct
37 Correct 70 ms 296412 KB Output is correct
38 Correct 241 ms 332880 KB Output is correct
39 Correct 165 ms 335700 KB Output is correct
40 Correct 169 ms 335820 KB Output is correct
41 Correct 163 ms 338768 KB Output is correct
42 Correct 181 ms 332596 KB Output is correct
43 Correct 178 ms 332628 KB Output is correct
44 Correct 150 ms 332628 KB Output is correct
45 Correct 149 ms 330752 KB Output is correct
46 Correct 216 ms 334132 KB Output is correct
47 Correct 257 ms 338928 KB Output is correct
48 Correct 434 ms 360436 KB Output is correct
49 Correct 416 ms 360988 KB Output is correct
50 Correct 242 ms 328812 KB Output is correct
51 Correct 236 ms 328684 KB Output is correct
52 Correct 371 ms 354116 KB Output is correct
53 Correct 396 ms 354384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 297040 KB Output is correct
2 Correct 41 ms 296852 KB Output is correct
3 Correct 42 ms 296652 KB Output is correct
4 Correct 42 ms 296276 KB Output is correct
5 Correct 43 ms 296920 KB Output is correct
6 Correct 43 ms 297044 KB Output is correct
7 Correct 44 ms 297044 KB Output is correct
8 Correct 46 ms 297044 KB Output is correct
9 Correct 44 ms 297008 KB Output is correct
10 Correct 40 ms 296540 KB Output is correct
11 Correct 42 ms 296780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 296280 KB Output is correct
2 Correct 75 ms 296336 KB Output is correct
3 Correct 56 ms 296420 KB Output is correct
4 Correct 76 ms 296480 KB Output is correct
5 Correct 70 ms 296412 KB Output is correct
6 Correct 39 ms 296528 KB Output is correct
7 Correct 1179 ms 510032 KB Output is correct
8 Correct 2597 ms 749652 KB Output is correct
9 Correct 2592 ms 751924 KB Output is correct
10 Correct 2573 ms 752168 KB Output is correct
11 Correct 332 ms 408148 KB Output is correct
12 Correct 713 ms 499492 KB Output is correct
13 Correct 795 ms 512708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 296248 KB Output is correct
2 Correct 56 ms 296532 KB Output is correct
3 Correct 58 ms 296524 KB Output is correct
4 Correct 78 ms 296352 KB Output is correct
5 Correct 56 ms 296528 KB Output is correct
6 Correct 56 ms 296536 KB Output is correct
7 Correct 56 ms 296532 KB Output is correct
8 Correct 56 ms 296276 KB Output is correct
9 Correct 61 ms 296528 KB Output is correct
10 Correct 55 ms 296528 KB Output is correct
11 Correct 55 ms 296532 KB Output is correct
12 Correct 53 ms 296532 KB Output is correct
13 Correct 72 ms 296380 KB Output is correct
14 Correct 43 ms 296252 KB Output is correct
15 Correct 55 ms 296304 KB Output is correct
16 Correct 55 ms 296280 KB Output is correct
17 Correct 63 ms 296784 KB Output is correct
18 Correct 54 ms 296884 KB Output is correct
19 Correct 53 ms 297048 KB Output is correct
20 Correct 61 ms 297044 KB Output is correct
21 Correct 59 ms 297304 KB Output is correct
22 Correct 59 ms 297300 KB Output is correct
23 Correct 54 ms 297196 KB Output is correct
24 Correct 73 ms 296728 KB Output is correct
25 Correct 57 ms 299088 KB Output is correct
26 Correct 51 ms 299028 KB Output is correct
27 Correct 73 ms 299092 KB Output is correct
28 Correct 72 ms 300112 KB Output is correct
29 Correct 82 ms 301392 KB Output is correct
30 Correct 83 ms 301520 KB Output is correct
31 Correct 80 ms 301056 KB Output is correct
32 Correct 81 ms 300928 KB Output is correct
33 Correct 241 ms 332880 KB Output is correct
34 Correct 165 ms 335700 KB Output is correct
35 Correct 169 ms 335820 KB Output is correct
36 Correct 163 ms 338768 KB Output is correct
37 Correct 181 ms 332596 KB Output is correct
38 Correct 178 ms 332628 KB Output is correct
39 Correct 150 ms 332628 KB Output is correct
40 Correct 149 ms 330752 KB Output is correct
41 Correct 216 ms 334132 KB Output is correct
42 Correct 257 ms 338928 KB Output is correct
43 Correct 434 ms 360436 KB Output is correct
44 Correct 416 ms 360988 KB Output is correct
45 Correct 242 ms 328812 KB Output is correct
46 Correct 236 ms 328684 KB Output is correct
47 Correct 371 ms 354116 KB Output is correct
48 Correct 396 ms 354384 KB Output is correct
49 Correct 47 ms 297040 KB Output is correct
50 Correct 41 ms 296852 KB Output is correct
51 Correct 42 ms 296652 KB Output is correct
52 Correct 42 ms 296276 KB Output is correct
53 Correct 43 ms 296920 KB Output is correct
54 Correct 43 ms 297044 KB Output is correct
55 Correct 44 ms 297044 KB Output is correct
56 Correct 46 ms 297044 KB Output is correct
57 Correct 44 ms 297008 KB Output is correct
58 Correct 40 ms 296540 KB Output is correct
59 Correct 42 ms 296780 KB Output is correct
60 Correct 39 ms 296528 KB Output is correct
61 Correct 1179 ms 510032 KB Output is correct
62 Correct 2597 ms 749652 KB Output is correct
63 Correct 2592 ms 751924 KB Output is correct
64 Correct 2573 ms 752168 KB Output is correct
65 Correct 332 ms 408148 KB Output is correct
66 Correct 713 ms 499492 KB Output is correct
67 Correct 795 ms 512708 KB Output is correct
68 Correct 72 ms 296280 KB Output is correct
69 Correct 75 ms 296336 KB Output is correct
70 Correct 56 ms 296420 KB Output is correct
71 Correct 76 ms 296480 KB Output is correct
72 Correct 70 ms 296412 KB Output is correct
73 Execution timed out 5037 ms 706120 KB Time limit exceeded
74 Halted 0 ms 0 KB -