Submission #1047439

# Submission time Handle Problem Language Result Execution time Memory
1047439 2024-08-07T13:05:22 Z vjudge1 Rectangles (IOI19_rect) C++17
59 / 100
3524 ms 1048576 KB
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("avx2")
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<Side> hsides[N][N];
vector<Side> 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());
	}
	for(int i = 0;i<n;i++) {
		for(auto pr:gdr[i]) {
			if(i!=n-1 and (*lower_bound(gdr[i+1].begin(), gdr[i+1].end(), pr)) == pr)continue;
			Side seg;
			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(seg);
			}
		}
	}





	for(int i = 0;i<m;i++) {
		for(auto pr:gdc[i]) {
			if(i!=m-1 and (*lower_bound(gdc[i+1].begin(), gdc[i+1].end(), pr)) == pr)continue;
			Side seg;
			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(seg);
			}
		}
	}


	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]) {
				if(k.r1+1 == k.r2)break;
				for(auto k2:hsides[i][j]) {
					if(k2.r1+1 == k2.r2)break;
					if(k2.r1 >= k.c1 and k2.c1 <= k.r1) {
//						cout << i << " " << k2.r1 << " " <<  k.r1 << " " << j <<  endl;
						ans++;
						tmp++;
					}

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

Compilation message

rect.cpp:5:28: warning: bad option '-favx2' to pragma 'optimize' [-Wpragmas]
    5 | #pragma GCC optimize("avx2")
      |                            ^
rect.cpp:17:60: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   17 | long long count_rectangles(std::vector<std::vector<int> > a) {
      |                                                            ^
# Verdict Execution time Memory Grader output
1 Correct 39 ms 296272 KB Output is correct
2 Correct 39 ms 296532 KB Output is correct
3 Correct 39 ms 296528 KB Output is correct
4 Correct 39 ms 296532 KB Output is correct
5 Correct 40 ms 296528 KB Output is correct
6 Correct 42 ms 296528 KB Output is correct
7 Correct 40 ms 296528 KB Output is correct
8 Correct 41 ms 296532 KB Output is correct
9 Correct 43 ms 296532 KB Output is correct
10 Correct 40 ms 296532 KB Output is correct
11 Correct 44 ms 296668 KB Output is correct
12 Correct 41 ms 296528 KB Output is correct
13 Correct 39 ms 296284 KB Output is correct
14 Correct 40 ms 296348 KB Output is correct
15 Correct 42 ms 296276 KB Output is correct
16 Correct 39 ms 296272 KB Output is correct
17 Correct 42 ms 296276 KB Output is correct
18 Correct 43 ms 296280 KB Output is correct
19 Correct 49 ms 296532 KB Output is correct
20 Correct 41 ms 296540 KB Output is correct
21 Correct 40 ms 296284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 296272 KB Output is correct
2 Correct 39 ms 296532 KB Output is correct
3 Correct 39 ms 296528 KB Output is correct
4 Correct 39 ms 296532 KB Output is correct
5 Correct 40 ms 296528 KB Output is correct
6 Correct 42 ms 296528 KB Output is correct
7 Correct 40 ms 296528 KB Output is correct
8 Correct 41 ms 296532 KB Output is correct
9 Correct 43 ms 296532 KB Output is correct
10 Correct 40 ms 296532 KB Output is correct
11 Correct 44 ms 296668 KB Output is correct
12 Correct 41 ms 296528 KB Output is correct
13 Correct 39 ms 296284 KB Output is correct
14 Correct 40 ms 296348 KB Output is correct
15 Correct 42 ms 296276 KB Output is correct
16 Correct 39 ms 296272 KB Output is correct
17 Correct 42 ms 296276 KB Output is correct
18 Correct 43 ms 296280 KB Output is correct
19 Correct 49 ms 296532 KB Output is correct
20 Correct 41 ms 296540 KB Output is correct
21 Correct 40 ms 296284 KB Output is correct
22 Correct 42 ms 297556 KB Output is correct
23 Correct 42 ms 297564 KB Output is correct
24 Correct 41 ms 297444 KB Output is correct
25 Correct 44 ms 297432 KB Output is correct
26 Correct 46 ms 297812 KB Output is correct
27 Correct 45 ms 297812 KB Output is correct
28 Correct 47 ms 297808 KB Output is correct
29 Correct 42 ms 297044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 296272 KB Output is correct
2 Correct 39 ms 296532 KB Output is correct
3 Correct 39 ms 296528 KB Output is correct
4 Correct 39 ms 296532 KB Output is correct
5 Correct 40 ms 296528 KB Output is correct
6 Correct 42 ms 296528 KB Output is correct
7 Correct 40 ms 296528 KB Output is correct
8 Correct 41 ms 296532 KB Output is correct
9 Correct 43 ms 296532 KB Output is correct
10 Correct 40 ms 296532 KB Output is correct
11 Correct 44 ms 296668 KB Output is correct
12 Correct 41 ms 296528 KB Output is correct
13 Correct 39 ms 296284 KB Output is correct
14 Correct 40 ms 296348 KB Output is correct
15 Correct 42 ms 296276 KB Output is correct
16 Correct 39 ms 296272 KB Output is correct
17 Correct 42 ms 297556 KB Output is correct
18 Correct 42 ms 297564 KB Output is correct
19 Correct 41 ms 297444 KB Output is correct
20 Correct 44 ms 297432 KB Output is correct
21 Correct 46 ms 297812 KB Output is correct
22 Correct 45 ms 297812 KB Output is correct
23 Correct 47 ms 297808 KB Output is correct
24 Correct 42 ms 297044 KB Output is correct
25 Correct 42 ms 296276 KB Output is correct
26 Correct 43 ms 296280 KB Output is correct
27 Correct 49 ms 296532 KB Output is correct
28 Correct 41 ms 296540 KB Output is correct
29 Correct 40 ms 296284 KB Output is correct
30 Correct 52 ms 302416 KB Output is correct
31 Correct 54 ms 302488 KB Output is correct
32 Correct 54 ms 302416 KB Output is correct
33 Correct 68 ms 302420 KB Output is correct
34 Correct 77 ms 304976 KB Output is correct
35 Correct 77 ms 305236 KB Output is correct
36 Correct 75 ms 304468 KB Output is correct
37 Correct 75 ms 304304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 296272 KB Output is correct
2 Correct 39 ms 296532 KB Output is correct
3 Correct 39 ms 296528 KB Output is correct
4 Correct 39 ms 296532 KB Output is correct
5 Correct 40 ms 296528 KB Output is correct
6 Correct 42 ms 296528 KB Output is correct
7 Correct 40 ms 296528 KB Output is correct
8 Correct 41 ms 296532 KB Output is correct
9 Correct 43 ms 296532 KB Output is correct
10 Correct 40 ms 296532 KB Output is correct
11 Correct 44 ms 296668 KB Output is correct
12 Correct 41 ms 296528 KB Output is correct
13 Correct 39 ms 296284 KB Output is correct
14 Correct 40 ms 296348 KB Output is correct
15 Correct 42 ms 296276 KB Output is correct
16 Correct 39 ms 296272 KB Output is correct
17 Correct 42 ms 297556 KB Output is correct
18 Correct 42 ms 297564 KB Output is correct
19 Correct 41 ms 297444 KB Output is correct
20 Correct 44 ms 297432 KB Output is correct
21 Correct 46 ms 297812 KB Output is correct
22 Correct 45 ms 297812 KB Output is correct
23 Correct 47 ms 297808 KB Output is correct
24 Correct 42 ms 297044 KB Output is correct
25 Correct 52 ms 302416 KB Output is correct
26 Correct 54 ms 302488 KB Output is correct
27 Correct 54 ms 302416 KB Output is correct
28 Correct 68 ms 302420 KB Output is correct
29 Correct 77 ms 304976 KB Output is correct
30 Correct 77 ms 305236 KB Output is correct
31 Correct 75 ms 304468 KB Output is correct
32 Correct 75 ms 304304 KB Output is correct
33 Correct 42 ms 296276 KB Output is correct
34 Correct 43 ms 296280 KB Output is correct
35 Correct 49 ms 296532 KB Output is correct
36 Correct 41 ms 296540 KB Output is correct
37 Correct 40 ms 296284 KB Output is correct
38 Correct 308 ms 378708 KB Output is correct
39 Correct 267 ms 373584 KB Output is correct
40 Correct 253 ms 374096 KB Output is correct
41 Correct 232 ms 369232 KB Output is correct
42 Correct 225 ms 373284 KB Output is correct
43 Correct 227 ms 373588 KB Output is correct
44 Correct 222 ms 373328 KB Output is correct
45 Correct 211 ms 369404 KB Output is correct
46 Correct 344 ms 359760 KB Output is correct
47 Correct 407 ms 368212 KB Output is correct
48 Correct 587 ms 406408 KB Output is correct
49 Correct 589 ms 407124 KB Output is correct
50 Correct 316 ms 351824 KB Output is correct
51 Correct 308 ms 351788 KB Output is correct
52 Correct 555 ms 395016 KB Output is correct
53 Correct 558 ms 395348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 297300 KB Output is correct
2 Correct 43 ms 297208 KB Output is correct
3 Correct 41 ms 297044 KB Output is correct
4 Correct 40 ms 296404 KB Output is correct
5 Correct 43 ms 297516 KB Output is correct
6 Correct 43 ms 297296 KB Output is correct
7 Correct 44 ms 297296 KB Output is correct
8 Correct 47 ms 297480 KB Output is correct
9 Correct 46 ms 297304 KB Output is correct
10 Correct 41 ms 296528 KB Output is correct
11 Correct 43 ms 297044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 296276 KB Output is correct
2 Correct 43 ms 296280 KB Output is correct
3 Correct 49 ms 296532 KB Output is correct
4 Correct 41 ms 296540 KB Output is correct
5 Correct 40 ms 296284 KB Output is correct
6 Correct 40 ms 296280 KB Output is correct
7 Correct 2074 ms 660560 KB Output is correct
8 Runtime error 3524 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 296272 KB Output is correct
2 Correct 39 ms 296532 KB Output is correct
3 Correct 39 ms 296528 KB Output is correct
4 Correct 39 ms 296532 KB Output is correct
5 Correct 40 ms 296528 KB Output is correct
6 Correct 42 ms 296528 KB Output is correct
7 Correct 40 ms 296528 KB Output is correct
8 Correct 41 ms 296532 KB Output is correct
9 Correct 43 ms 296532 KB Output is correct
10 Correct 40 ms 296532 KB Output is correct
11 Correct 44 ms 296668 KB Output is correct
12 Correct 41 ms 296528 KB Output is correct
13 Correct 39 ms 296284 KB Output is correct
14 Correct 40 ms 296348 KB Output is correct
15 Correct 42 ms 296276 KB Output is correct
16 Correct 39 ms 296272 KB Output is correct
17 Correct 42 ms 297556 KB Output is correct
18 Correct 42 ms 297564 KB Output is correct
19 Correct 41 ms 297444 KB Output is correct
20 Correct 44 ms 297432 KB Output is correct
21 Correct 46 ms 297812 KB Output is correct
22 Correct 45 ms 297812 KB Output is correct
23 Correct 47 ms 297808 KB Output is correct
24 Correct 42 ms 297044 KB Output is correct
25 Correct 52 ms 302416 KB Output is correct
26 Correct 54 ms 302488 KB Output is correct
27 Correct 54 ms 302416 KB Output is correct
28 Correct 68 ms 302420 KB Output is correct
29 Correct 77 ms 304976 KB Output is correct
30 Correct 77 ms 305236 KB Output is correct
31 Correct 75 ms 304468 KB Output is correct
32 Correct 75 ms 304304 KB Output is correct
33 Correct 308 ms 378708 KB Output is correct
34 Correct 267 ms 373584 KB Output is correct
35 Correct 253 ms 374096 KB Output is correct
36 Correct 232 ms 369232 KB Output is correct
37 Correct 225 ms 373284 KB Output is correct
38 Correct 227 ms 373588 KB Output is correct
39 Correct 222 ms 373328 KB Output is correct
40 Correct 211 ms 369404 KB Output is correct
41 Correct 344 ms 359760 KB Output is correct
42 Correct 407 ms 368212 KB Output is correct
43 Correct 587 ms 406408 KB Output is correct
44 Correct 589 ms 407124 KB Output is correct
45 Correct 316 ms 351824 KB Output is correct
46 Correct 308 ms 351788 KB Output is correct
47 Correct 555 ms 395016 KB Output is correct
48 Correct 558 ms 395348 KB Output is correct
49 Correct 43 ms 297300 KB Output is correct
50 Correct 43 ms 297208 KB Output is correct
51 Correct 41 ms 297044 KB Output is correct
52 Correct 40 ms 296404 KB Output is correct
53 Correct 43 ms 297516 KB Output is correct
54 Correct 43 ms 297296 KB Output is correct
55 Correct 44 ms 297296 KB Output is correct
56 Correct 47 ms 297480 KB Output is correct
57 Correct 46 ms 297304 KB Output is correct
58 Correct 41 ms 296528 KB Output is correct
59 Correct 43 ms 297044 KB Output is correct
60 Correct 40 ms 296280 KB Output is correct
61 Correct 2074 ms 660560 KB Output is correct
62 Runtime error 3524 ms 1048576 KB Execution killed with signal 9
63 Halted 0 ms 0 KB -