답안 #843627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
843627 2023-09-04T09:26:38 Z siewjh Rectangles (IOI19_rect) C++17
100 / 100
2909 ms 1004852 KB
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2505;
int rows, cols;
ll fw[MAXN];
vector<int> prs[MAXN][MAXN];
vector<pair<int, int>> lrc[MAXN][MAXN], tbc[MAXN][MAXN];

void update(int x, ll v){
	while (x < cols){
		fw[x] += v;
		x += (x & (-x));
	}
}

void rupdate(int x, int y, ll v){
	update(x, v); update(y + 1, -v);
}

ll query(int x){
	ll ans = 0;
	while (x){
		ans += fw[x];
		x -= (x & (-x));
	}
	return ans;
}

ll count_rectangles(vector<vector<int>> a) {
	rows = a.size(), cols = a[0].size();
	for (int i = 0; i < rows; i++){
		stack<int> s;
		for (int j = 0; j < cols; j++){
			while (!s.empty() && a[i][j] > a[i][s.top()]) s.pop();
			if (!s.empty() && s.top() + 1 != j) prs[s.top()][j].push_back(i);
			s.push(j);
		}
		while (!s.empty()) s.pop();
		for (int j = cols - 1; j >= 0; j--){
			bool same = false;
			while (!s.empty() && a[i][j] >= a[i][s.top()]){
				if (a[i][j] == a[i][s.top()]) same = true;
				s.pop();
			}
			if (!same && !s.empty() && s.top() - 1 != j) prs[j][s.top()].push_back(i);
			s.push(j);
		}
	}
	for (int i = 0; i < cols; i++)
		for (int j = i + 2; j < cols; j++){
			int sz = prs[i][j].size();
			for (int s = 0; s < sz; s++){
				int e = s;
				while (e != sz - 1 && prs[i][j][e + 1] == prs[i][j][e] + 1) e++;
				for (int k = s; k <= e; k++) lrc[prs[i][j][k]][i + 1].push_back({prs[i][j][e], j - 1});
				s = e;
			}
		}
	for (int j = 0; j < cols; j++){
		stack<int> s;
		for (int i = 0; i < rows; i++){
			while (!s.empty() && a[i][j] > a[s.top()][j]) s.pop();
			if (!s.empty() && s.top() + 1 != i) prs[i][s.top()].push_back(j);
			s.push(i);
		}
		for (int i = rows - 1; i >= 0; i--){
			bool same = 0;
			while (!s.empty() && a[i][j] >= a[s.top()][j]){
				if (a[i][j] == a[s.top()][j]) same = 1;
				s.pop();
			}
			if (!same && !s.empty() && s.top() - 1 != i) prs[s.top()][i].push_back(j);
			s.push(i);
		}
	}
	for (int i = 0; i < rows; i++)
		for (int j = i + 2; j < rows; j++){
			int sz = prs[j][i].size();
			for (int s = 0; s < sz; s++){
				int e = s;
				while (e != sz - 1 && prs[j][i][e + 1] == prs[j][i][e] + 1) e++;
				for (int k = s; k <= e; k++) tbc[i + 1][prs[j][i][k]].push_back({j - 1, prs[j][i][e]});
				s = e;
			}
		}
	ll ans = 0;
	for (int i = 1; i < rows - 1; i++)
		for (int j = 1; j < cols - 1; j++){
			sort(lrc[i][j].begin(), lrc[i][j].end());
			sort(tbc[i][j].begin(), tbc[i][j].end());
			int ind = 0;
			for (auto p : lrc[i][j]){
				int r, c; tie(r, c) = p;
				while (ind != tbc[i][j].size() && tbc[i][j][ind].first <= r){
					rupdate(1, tbc[i][j][ind].second, 1);
					ind++;
				}
				ans += query(c);
			}
			for (int k = 0; k < ind; k++) rupdate(1, tbc[i][j][k].second, -1);
		}
	return ans;
}

Compilation message

rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:96:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     while (ind != tbc[i][j].size() && tbc[i][j][ind].first <= r){
      |            ~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 442448 KB Output is correct
2 Correct 92 ms 442448 KB Output is correct
3 Correct 92 ms 442448 KB Output is correct
4 Correct 95 ms 442480 KB Output is correct
5 Correct 92 ms 442404 KB Output is correct
6 Correct 92 ms 442368 KB Output is correct
7 Correct 92 ms 442448 KB Output is correct
8 Correct 92 ms 442428 KB Output is correct
9 Correct 94 ms 442448 KB Output is correct
10 Correct 91 ms 442448 KB Output is correct
11 Correct 91 ms 442448 KB Output is correct
12 Correct 92 ms 442432 KB Output is correct
13 Correct 94 ms 442492 KB Output is correct
14 Correct 93 ms 442436 KB Output is correct
15 Correct 92 ms 442708 KB Output is correct
16 Correct 91 ms 442360 KB Output is correct
17 Correct 93 ms 442448 KB Output is correct
18 Correct 92 ms 442356 KB Output is correct
19 Correct 93 ms 442452 KB Output is correct
20 Correct 93 ms 442448 KB Output is correct
21 Correct 93 ms 442444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 442448 KB Output is correct
2 Correct 92 ms 442448 KB Output is correct
3 Correct 92 ms 442448 KB Output is correct
4 Correct 95 ms 442480 KB Output is correct
5 Correct 92 ms 442404 KB Output is correct
6 Correct 92 ms 442368 KB Output is correct
7 Correct 92 ms 442448 KB Output is correct
8 Correct 92 ms 442428 KB Output is correct
9 Correct 94 ms 442448 KB Output is correct
10 Correct 91 ms 442448 KB Output is correct
11 Correct 91 ms 442448 KB Output is correct
12 Correct 92 ms 442432 KB Output is correct
13 Correct 94 ms 442492 KB Output is correct
14 Correct 93 ms 442436 KB Output is correct
15 Correct 92 ms 442708 KB Output is correct
16 Correct 91 ms 442360 KB Output is correct
17 Correct 93 ms 442448 KB Output is correct
18 Correct 92 ms 442356 KB Output is correct
19 Correct 93 ms 442452 KB Output is correct
20 Correct 93 ms 442448 KB Output is correct
21 Correct 93 ms 442444 KB Output is correct
22 Correct 93 ms 443012 KB Output is correct
23 Correct 92 ms 442960 KB Output is correct
24 Correct 93 ms 442876 KB Output is correct
25 Correct 97 ms 442616 KB Output is correct
26 Correct 98 ms 442704 KB Output is correct
27 Correct 94 ms 442792 KB Output is correct
28 Correct 94 ms 442768 KB Output is correct
29 Correct 91 ms 442448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 442448 KB Output is correct
2 Correct 92 ms 442448 KB Output is correct
3 Correct 92 ms 442448 KB Output is correct
4 Correct 95 ms 442480 KB Output is correct
5 Correct 92 ms 442404 KB Output is correct
6 Correct 92 ms 442368 KB Output is correct
7 Correct 92 ms 442448 KB Output is correct
8 Correct 92 ms 442428 KB Output is correct
9 Correct 94 ms 442448 KB Output is correct
10 Correct 91 ms 442448 KB Output is correct
11 Correct 91 ms 442448 KB Output is correct
12 Correct 92 ms 442432 KB Output is correct
13 Correct 94 ms 442492 KB Output is correct
14 Correct 93 ms 442436 KB Output is correct
15 Correct 92 ms 442708 KB Output is correct
16 Correct 91 ms 442360 KB Output is correct
17 Correct 93 ms 443012 KB Output is correct
18 Correct 92 ms 442960 KB Output is correct
19 Correct 93 ms 442876 KB Output is correct
20 Correct 97 ms 442616 KB Output is correct
21 Correct 98 ms 442704 KB Output is correct
22 Correct 94 ms 442792 KB Output is correct
23 Correct 94 ms 442768 KB Output is correct
24 Correct 91 ms 442448 KB Output is correct
25 Correct 93 ms 442448 KB Output is correct
26 Correct 92 ms 442356 KB Output is correct
27 Correct 93 ms 442452 KB Output is correct
28 Correct 93 ms 442448 KB Output is correct
29 Correct 93 ms 442444 KB Output is correct
30 Correct 100 ms 445784 KB Output is correct
31 Correct 100 ms 445776 KB Output is correct
32 Correct 100 ms 445884 KB Output is correct
33 Correct 100 ms 443756 KB Output is correct
34 Correct 104 ms 445008 KB Output is correct
35 Correct 105 ms 445008 KB Output is correct
36 Correct 103 ms 444820 KB Output is correct
37 Correct 104 ms 444908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 442448 KB Output is correct
2 Correct 92 ms 442448 KB Output is correct
3 Correct 92 ms 442448 KB Output is correct
4 Correct 95 ms 442480 KB Output is correct
5 Correct 92 ms 442404 KB Output is correct
6 Correct 92 ms 442368 KB Output is correct
7 Correct 92 ms 442448 KB Output is correct
8 Correct 92 ms 442428 KB Output is correct
9 Correct 94 ms 442448 KB Output is correct
10 Correct 91 ms 442448 KB Output is correct
11 Correct 91 ms 442448 KB Output is correct
12 Correct 92 ms 442432 KB Output is correct
13 Correct 94 ms 442492 KB Output is correct
14 Correct 93 ms 442436 KB Output is correct
15 Correct 92 ms 442708 KB Output is correct
16 Correct 91 ms 442360 KB Output is correct
17 Correct 93 ms 443012 KB Output is correct
18 Correct 92 ms 442960 KB Output is correct
19 Correct 93 ms 442876 KB Output is correct
20 Correct 97 ms 442616 KB Output is correct
21 Correct 98 ms 442704 KB Output is correct
22 Correct 94 ms 442792 KB Output is correct
23 Correct 94 ms 442768 KB Output is correct
24 Correct 91 ms 442448 KB Output is correct
25 Correct 100 ms 445784 KB Output is correct
26 Correct 100 ms 445776 KB Output is correct
27 Correct 100 ms 445884 KB Output is correct
28 Correct 100 ms 443756 KB Output is correct
29 Correct 104 ms 445008 KB Output is correct
30 Correct 105 ms 445008 KB Output is correct
31 Correct 103 ms 444820 KB Output is correct
32 Correct 104 ms 444908 KB Output is correct
33 Correct 93 ms 442448 KB Output is correct
34 Correct 92 ms 442356 KB Output is correct
35 Correct 93 ms 442452 KB Output is correct
36 Correct 93 ms 442448 KB Output is correct
37 Correct 93 ms 442444 KB Output is correct
38 Correct 193 ms 478700 KB Output is correct
39 Correct 172 ms 473908 KB Output is correct
40 Correct 191 ms 473768 KB Output is correct
41 Correct 157 ms 469076 KB Output is correct
42 Correct 197 ms 484176 KB Output is correct
43 Correct 191 ms 484176 KB Output is correct
44 Correct 193 ms 484404 KB Output is correct
45 Correct 189 ms 482132 KB Output is correct
46 Correct 165 ms 456272 KB Output is correct
47 Correct 182 ms 459604 KB Output is correct
48 Correct 265 ms 471728 KB Output is correct
49 Correct 277 ms 472832 KB Output is correct
50 Correct 182 ms 458164 KB Output is correct
51 Correct 180 ms 458064 KB Output is correct
52 Correct 254 ms 470084 KB Output is correct
53 Correct 251 ms 470308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 442960 KB Output is correct
2 Correct 97 ms 442960 KB Output is correct
3 Correct 104 ms 442704 KB Output is correct
4 Correct 92 ms 442444 KB Output is correct
5 Correct 100 ms 442932 KB Output is correct
6 Correct 101 ms 442960 KB Output is correct
7 Correct 106 ms 442960 KB Output is correct
8 Correct 101 ms 442840 KB Output is correct
9 Correct 100 ms 442868 KB Output is correct
10 Correct 99 ms 442448 KB Output is correct
11 Correct 103 ms 442704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 442448 KB Output is correct
2 Correct 92 ms 442356 KB Output is correct
3 Correct 93 ms 442452 KB Output is correct
4 Correct 93 ms 442448 KB Output is correct
5 Correct 93 ms 442444 KB Output is correct
6 Correct 93 ms 442452 KB Output is correct
7 Correct 566 ms 522808 KB Output is correct
8 Correct 1150 ms 615384 KB Output is correct
9 Correct 1160 ms 616436 KB Output is correct
10 Correct 1190 ms 616152 KB Output is correct
11 Correct 211 ms 470060 KB Output is correct
12 Correct 367 ms 494468 KB Output is correct
13 Correct 392 ms 498012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 442448 KB Output is correct
2 Correct 92 ms 442448 KB Output is correct
3 Correct 92 ms 442448 KB Output is correct
4 Correct 95 ms 442480 KB Output is correct
5 Correct 92 ms 442404 KB Output is correct
6 Correct 92 ms 442368 KB Output is correct
7 Correct 92 ms 442448 KB Output is correct
8 Correct 92 ms 442428 KB Output is correct
9 Correct 94 ms 442448 KB Output is correct
10 Correct 91 ms 442448 KB Output is correct
11 Correct 91 ms 442448 KB Output is correct
12 Correct 92 ms 442432 KB Output is correct
13 Correct 94 ms 442492 KB Output is correct
14 Correct 93 ms 442436 KB Output is correct
15 Correct 92 ms 442708 KB Output is correct
16 Correct 91 ms 442360 KB Output is correct
17 Correct 93 ms 443012 KB Output is correct
18 Correct 92 ms 442960 KB Output is correct
19 Correct 93 ms 442876 KB Output is correct
20 Correct 97 ms 442616 KB Output is correct
21 Correct 98 ms 442704 KB Output is correct
22 Correct 94 ms 442792 KB Output is correct
23 Correct 94 ms 442768 KB Output is correct
24 Correct 91 ms 442448 KB Output is correct
25 Correct 100 ms 445784 KB Output is correct
26 Correct 100 ms 445776 KB Output is correct
27 Correct 100 ms 445884 KB Output is correct
28 Correct 100 ms 443756 KB Output is correct
29 Correct 104 ms 445008 KB Output is correct
30 Correct 105 ms 445008 KB Output is correct
31 Correct 103 ms 444820 KB Output is correct
32 Correct 104 ms 444908 KB Output is correct
33 Correct 193 ms 478700 KB Output is correct
34 Correct 172 ms 473908 KB Output is correct
35 Correct 191 ms 473768 KB Output is correct
36 Correct 157 ms 469076 KB Output is correct
37 Correct 197 ms 484176 KB Output is correct
38 Correct 191 ms 484176 KB Output is correct
39 Correct 193 ms 484404 KB Output is correct
40 Correct 189 ms 482132 KB Output is correct
41 Correct 165 ms 456272 KB Output is correct
42 Correct 182 ms 459604 KB Output is correct
43 Correct 265 ms 471728 KB Output is correct
44 Correct 277 ms 472832 KB Output is correct
45 Correct 182 ms 458164 KB Output is correct
46 Correct 180 ms 458064 KB Output is correct
47 Correct 254 ms 470084 KB Output is correct
48 Correct 251 ms 470308 KB Output is correct
49 Correct 100 ms 442960 KB Output is correct
50 Correct 97 ms 442960 KB Output is correct
51 Correct 104 ms 442704 KB Output is correct
52 Correct 92 ms 442444 KB Output is correct
53 Correct 100 ms 442932 KB Output is correct
54 Correct 101 ms 442960 KB Output is correct
55 Correct 106 ms 442960 KB Output is correct
56 Correct 101 ms 442840 KB Output is correct
57 Correct 100 ms 442868 KB Output is correct
58 Correct 99 ms 442448 KB Output is correct
59 Correct 103 ms 442704 KB Output is correct
60 Correct 93 ms 442452 KB Output is correct
61 Correct 566 ms 522808 KB Output is correct
62 Correct 1150 ms 615384 KB Output is correct
63 Correct 1160 ms 616436 KB Output is correct
64 Correct 1190 ms 616152 KB Output is correct
65 Correct 211 ms 470060 KB Output is correct
66 Correct 367 ms 494468 KB Output is correct
67 Correct 392 ms 498012 KB Output is correct
68 Correct 93 ms 442448 KB Output is correct
69 Correct 92 ms 442356 KB Output is correct
70 Correct 93 ms 442452 KB Output is correct
71 Correct 93 ms 442448 KB Output is correct
72 Correct 93 ms 442444 KB Output is correct
73 Correct 1783 ms 920432 KB Output is correct
74 Correct 1285 ms 839020 KB Output is correct
75 Correct 1691 ms 839156 KB Output is correct
76 Correct 1108 ms 772176 KB Output is correct
77 Correct 2196 ms 1004772 KB Output is correct
78 Correct 1666 ms 670044 KB Output is correct
79 Correct 1734 ms 695296 KB Output is correct
80 Correct 2776 ms 819336 KB Output is correct
81 Correct 1741 ms 687740 KB Output is correct
82 Correct 2259 ms 770736 KB Output is correct
83 Correct 2909 ms 848872 KB Output is correct
84 Correct 1487 ms 662084 KB Output is correct
85 Correct 2565 ms 823516 KB Output is correct
86 Correct 2482 ms 812084 KB Output is correct
87 Correct 1292 ms 777672 KB Output is correct
88 Correct 2356 ms 1004616 KB Output is correct
89 Correct 2231 ms 1004796 KB Output is correct
90 Correct 2201 ms 1004852 KB Output is correct