답안 #1047689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047689 2024-08-07T15:03:15 Z fuad27 Rectangles (IOI19_rect) C++17
72 / 100
5000 ms 797780 KB
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int N = 2510;
int n,m;
vector<array<int, 2>> gdr[N][N];
vector<array<int, 2>> gdc[N][N];

struct Side {
	int r1, r2, c1, c2;
};


int fen[N];
void upd(int at, int add) {
	at++;
	while(at) {
		fen[at]+=add;
		at-=at&(-at);
	}
}
int qry(int at) {
	at++;
	int sum=0;
	while(at<N) {
		sum+=fen[at];
		at+=at&(-at);
	}
	return sum;
}
vector<int> stk;
long long count_rectangles(std::vector<std::vector<int> > a) {
	n = a.size();
	m = a[0].size();
	for(int i = 0;i<n;i++) {
			stk.clear();
		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][j].push_back({stk.back(), 1});
			}
			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][stk.back()].push_back({j,1});
				}
			}
			stk.push_back(j);
		}
	}
	for(int i = 0;i<m;i++) {
			stk.clear();
		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[j][i].push_back({stk.back(),1});
			}
			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()) {
				if(a[j][i] != a[stk.back()][i]) {
					gdc[stk.back()][i].push_back({j, 1});
				}
			}
			stk.push_back(j);
		}
	}


	long long ans=0;
	for(int i = 0;i<n;i++) {
		for(int j = 0;j<m;j++) {
		sort(gdr[i][j].begin(), gdr[i][j].end());
		sort(gdc[i][j].begin(), gdc[i][j].end());
		gdr[i][j].erase(unique(gdr[i][j].begin(), gdr[i][j].end()), gdr[i][j].end());
		gdc[i][j].erase(unique(gdc[i][j].begin(), gdc[i][j].end()), gdc[i][j].end());
		if(i) {
				for(auto &[u, v]:gdr[i][j]) {
					auto it = lower_bound(gdr[i-1][j].begin(), gdr[i-1][j].end(), array<int,2>{u, 0});
					if(it!=gdr[i-1][j].end() and (*it)[0] == u) {
						v+=(*it)[1];
					}
				}
			}
			if(j) {
				for(auto &[u, v]:gdc[i][j]) {
					auto it = lower_bound(gdc[i][j-1].begin(), gdc[i][j-1].end(), array<int,2>{u, 0});
					if(it!=gdc[i][j-1].end() and (*it)[0] == u) {
						v+=(*it)[1];
					}
				}
			}
			if(i and j) {
				for(auto k:gdr[i-1][j]) {
					if(k[0] +1 == j)continue;
					for(auto k2:gdc[i][j-1]) {
						if(k2[0] +1 == i)continue;
//						cout << i << " " << j << " " << k[0] << " " <<  k2[0] << " " << k[1] << " " << k2[1] << endl;
						if(k[0] >= j - k2[1]-1 and k2[0] >= i - k[1] - 1)ans++;
					}
				}
			}
		}
	}
	return ans;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 296188 KB Output is correct
2 Correct 53 ms 296280 KB Output is correct
3 Correct 51 ms 296276 KB Output is correct
4 Correct 54 ms 296272 KB Output is correct
5 Correct 40 ms 296160 KB Output is correct
6 Correct 41 ms 296200 KB Output is correct
7 Correct 46 ms 296296 KB Output is correct
8 Correct 42 ms 296284 KB Output is correct
9 Correct 43 ms 296272 KB Output is correct
10 Correct 40 ms 296156 KB Output is correct
11 Correct 42 ms 296212 KB Output is correct
12 Correct 44 ms 296272 KB Output is correct
13 Correct 43 ms 296280 KB Output is correct
14 Correct 47 ms 296080 KB Output is correct
15 Correct 40 ms 296272 KB Output is correct
16 Correct 40 ms 296284 KB Output is correct
17 Correct 40 ms 296276 KB Output is correct
18 Correct 39 ms 296276 KB Output is correct
19 Correct 41 ms 296276 KB Output is correct
20 Correct 40 ms 296276 KB Output is correct
21 Correct 42 ms 296276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 296188 KB Output is correct
2 Correct 53 ms 296280 KB Output is correct
3 Correct 51 ms 296276 KB Output is correct
4 Correct 54 ms 296272 KB Output is correct
5 Correct 40 ms 296160 KB Output is correct
6 Correct 41 ms 296200 KB Output is correct
7 Correct 46 ms 296296 KB Output is correct
8 Correct 42 ms 296284 KB Output is correct
9 Correct 43 ms 296272 KB Output is correct
10 Correct 40 ms 296156 KB Output is correct
11 Correct 42 ms 296212 KB Output is correct
12 Correct 44 ms 296272 KB Output is correct
13 Correct 43 ms 296280 KB Output is correct
14 Correct 47 ms 296080 KB Output is correct
15 Correct 40 ms 296272 KB Output is correct
16 Correct 40 ms 296284 KB Output is correct
17 Correct 40 ms 296276 KB Output is correct
18 Correct 39 ms 296276 KB Output is correct
19 Correct 41 ms 296276 KB Output is correct
20 Correct 40 ms 296276 KB Output is correct
21 Correct 42 ms 296276 KB Output is correct
22 Correct 42 ms 296788 KB Output is correct
23 Correct 41 ms 296792 KB Output is correct
24 Correct 41 ms 296932 KB Output is correct
25 Correct 41 ms 296532 KB Output is correct
26 Correct 41 ms 296784 KB Output is correct
27 Correct 45 ms 296788 KB Output is correct
28 Correct 41 ms 296788 KB Output is correct
29 Correct 41 ms 296540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 296188 KB Output is correct
2 Correct 53 ms 296280 KB Output is correct
3 Correct 51 ms 296276 KB Output is correct
4 Correct 54 ms 296272 KB Output is correct
5 Correct 40 ms 296160 KB Output is correct
6 Correct 41 ms 296200 KB Output is correct
7 Correct 46 ms 296296 KB Output is correct
8 Correct 42 ms 296284 KB Output is correct
9 Correct 43 ms 296272 KB Output is correct
10 Correct 40 ms 296156 KB Output is correct
11 Correct 42 ms 296212 KB Output is correct
12 Correct 44 ms 296272 KB Output is correct
13 Correct 43 ms 296280 KB Output is correct
14 Correct 47 ms 296080 KB Output is correct
15 Correct 40 ms 296272 KB Output is correct
16 Correct 40 ms 296284 KB Output is correct
17 Correct 42 ms 296788 KB Output is correct
18 Correct 41 ms 296792 KB Output is correct
19 Correct 41 ms 296932 KB Output is correct
20 Correct 41 ms 296532 KB Output is correct
21 Correct 41 ms 296784 KB Output is correct
22 Correct 45 ms 296788 KB Output is correct
23 Correct 41 ms 296788 KB Output is correct
24 Correct 41 ms 296540 KB Output is correct
25 Correct 40 ms 296276 KB Output is correct
26 Correct 39 ms 296276 KB Output is correct
27 Correct 41 ms 296276 KB Output is correct
28 Correct 40 ms 296276 KB Output is correct
29 Correct 42 ms 296276 KB Output is correct
30 Correct 47 ms 299860 KB Output is correct
31 Correct 53 ms 299824 KB Output is correct
32 Correct 47 ms 299860 KB Output is correct
33 Correct 51 ms 299100 KB Output is correct
34 Correct 50 ms 299376 KB Output is correct
35 Correct 51 ms 299344 KB Output is correct
36 Correct 52 ms 299344 KB Output is correct
37 Correct 51 ms 299344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 296188 KB Output is correct
2 Correct 53 ms 296280 KB Output is correct
3 Correct 51 ms 296276 KB Output is correct
4 Correct 54 ms 296272 KB Output is correct
5 Correct 40 ms 296160 KB Output is correct
6 Correct 41 ms 296200 KB Output is correct
7 Correct 46 ms 296296 KB Output is correct
8 Correct 42 ms 296284 KB Output is correct
9 Correct 43 ms 296272 KB Output is correct
10 Correct 40 ms 296156 KB Output is correct
11 Correct 42 ms 296212 KB Output is correct
12 Correct 44 ms 296272 KB Output is correct
13 Correct 43 ms 296280 KB Output is correct
14 Correct 47 ms 296080 KB Output is correct
15 Correct 40 ms 296272 KB Output is correct
16 Correct 40 ms 296284 KB Output is correct
17 Correct 42 ms 296788 KB Output is correct
18 Correct 41 ms 296792 KB Output is correct
19 Correct 41 ms 296932 KB Output is correct
20 Correct 41 ms 296532 KB Output is correct
21 Correct 41 ms 296784 KB Output is correct
22 Correct 45 ms 296788 KB Output is correct
23 Correct 41 ms 296788 KB Output is correct
24 Correct 41 ms 296540 KB Output is correct
25 Correct 47 ms 299860 KB Output is correct
26 Correct 53 ms 299824 KB Output is correct
27 Correct 47 ms 299860 KB Output is correct
28 Correct 51 ms 299100 KB Output is correct
29 Correct 50 ms 299376 KB Output is correct
30 Correct 51 ms 299344 KB Output is correct
31 Correct 52 ms 299344 KB Output is correct
32 Correct 51 ms 299344 KB Output is correct
33 Correct 40 ms 296276 KB Output is correct
34 Correct 39 ms 296276 KB Output is correct
35 Correct 41 ms 296276 KB Output is correct
36 Correct 40 ms 296276 KB Output is correct
37 Correct 42 ms 296276 KB Output is correct
38 Correct 213 ms 336564 KB Output is correct
39 Correct 113 ms 333656 KB Output is correct
40 Correct 114 ms 333652 KB Output is correct
41 Correct 108 ms 330796 KB Output is correct
42 Correct 132 ms 341840 KB Output is correct
43 Correct 130 ms 341748 KB Output is correct
44 Correct 133 ms 342096 KB Output is correct
45 Correct 128 ms 339284 KB Output is correct
46 Correct 116 ms 330832 KB Output is correct
47 Correct 138 ms 331520 KB Output is correct
48 Correct 197 ms 336464 KB Output is correct
49 Correct 192 ms 336468 KB Output is correct
50 Correct 109 ms 316416 KB Output is correct
51 Correct 111 ms 316420 KB Output is correct
52 Correct 228 ms 336148 KB Output is correct
53 Correct 194 ms 336212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 296784 KB Output is correct
2 Correct 45 ms 296532 KB Output is correct
3 Correct 40 ms 296532 KB Output is correct
4 Correct 39 ms 296284 KB Output is correct
5 Correct 43 ms 296796 KB Output is correct
6 Correct 44 ms 296680 KB Output is correct
7 Correct 42 ms 296784 KB Output is correct
8 Correct 41 ms 296788 KB Output is correct
9 Correct 40 ms 296784 KB Output is correct
10 Correct 41 ms 296284 KB Output is correct
11 Correct 40 ms 296540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 296276 KB Output is correct
2 Correct 39 ms 296276 KB Output is correct
3 Correct 41 ms 296276 KB Output is correct
4 Correct 40 ms 296276 KB Output is correct
5 Correct 42 ms 296276 KB Output is correct
6 Correct 44 ms 296276 KB Output is correct
7 Correct 631 ms 498000 KB Output is correct
8 Correct 1292 ms 734248 KB Output is correct
9 Correct 1315 ms 736456 KB Output is correct
10 Correct 1287 ms 736596 KB Output is correct
11 Correct 356 ms 513620 KB Output is correct
12 Correct 657 ms 709200 KB Output is correct
13 Correct 696 ms 736620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 296188 KB Output is correct
2 Correct 53 ms 296280 KB Output is correct
3 Correct 51 ms 296276 KB Output is correct
4 Correct 54 ms 296272 KB Output is correct
5 Correct 40 ms 296160 KB Output is correct
6 Correct 41 ms 296200 KB Output is correct
7 Correct 46 ms 296296 KB Output is correct
8 Correct 42 ms 296284 KB Output is correct
9 Correct 43 ms 296272 KB Output is correct
10 Correct 40 ms 296156 KB Output is correct
11 Correct 42 ms 296212 KB Output is correct
12 Correct 44 ms 296272 KB Output is correct
13 Correct 43 ms 296280 KB Output is correct
14 Correct 47 ms 296080 KB Output is correct
15 Correct 40 ms 296272 KB Output is correct
16 Correct 40 ms 296284 KB Output is correct
17 Correct 42 ms 296788 KB Output is correct
18 Correct 41 ms 296792 KB Output is correct
19 Correct 41 ms 296932 KB Output is correct
20 Correct 41 ms 296532 KB Output is correct
21 Correct 41 ms 296784 KB Output is correct
22 Correct 45 ms 296788 KB Output is correct
23 Correct 41 ms 296788 KB Output is correct
24 Correct 41 ms 296540 KB Output is correct
25 Correct 47 ms 299860 KB Output is correct
26 Correct 53 ms 299824 KB Output is correct
27 Correct 47 ms 299860 KB Output is correct
28 Correct 51 ms 299100 KB Output is correct
29 Correct 50 ms 299376 KB Output is correct
30 Correct 51 ms 299344 KB Output is correct
31 Correct 52 ms 299344 KB Output is correct
32 Correct 51 ms 299344 KB Output is correct
33 Correct 213 ms 336564 KB Output is correct
34 Correct 113 ms 333656 KB Output is correct
35 Correct 114 ms 333652 KB Output is correct
36 Correct 108 ms 330796 KB Output is correct
37 Correct 132 ms 341840 KB Output is correct
38 Correct 130 ms 341748 KB Output is correct
39 Correct 133 ms 342096 KB Output is correct
40 Correct 128 ms 339284 KB Output is correct
41 Correct 116 ms 330832 KB Output is correct
42 Correct 138 ms 331520 KB Output is correct
43 Correct 197 ms 336464 KB Output is correct
44 Correct 192 ms 336468 KB Output is correct
45 Correct 109 ms 316416 KB Output is correct
46 Correct 111 ms 316420 KB Output is correct
47 Correct 228 ms 336148 KB Output is correct
48 Correct 194 ms 336212 KB Output is correct
49 Correct 43 ms 296784 KB Output is correct
50 Correct 45 ms 296532 KB Output is correct
51 Correct 40 ms 296532 KB Output is correct
52 Correct 39 ms 296284 KB Output is correct
53 Correct 43 ms 296796 KB Output is correct
54 Correct 44 ms 296680 KB Output is correct
55 Correct 42 ms 296784 KB Output is correct
56 Correct 41 ms 296788 KB Output is correct
57 Correct 40 ms 296784 KB Output is correct
58 Correct 41 ms 296284 KB Output is correct
59 Correct 40 ms 296540 KB Output is correct
60 Correct 44 ms 296276 KB Output is correct
61 Correct 631 ms 498000 KB Output is correct
62 Correct 1292 ms 734248 KB Output is correct
63 Correct 1315 ms 736456 KB Output is correct
64 Correct 1287 ms 736596 KB Output is correct
65 Correct 356 ms 513620 KB Output is correct
66 Correct 657 ms 709200 KB Output is correct
67 Correct 696 ms 736620 KB Output is correct
68 Correct 40 ms 296276 KB Output is correct
69 Correct 39 ms 296276 KB Output is correct
70 Correct 41 ms 296276 KB Output is correct
71 Correct 40 ms 296276 KB Output is correct
72 Correct 42 ms 296276 KB Output is correct
73 Execution timed out 5085 ms 797780 KB Time limit exceeded
74 Halted 0 ms 0 KB -