# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032403 | 2024-07-23T17:01:58 Z | shmax | Rectangles (IOI19_rect) | C++17 | 5000 ms | 883832 KB |
#include "rect.h" #include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,bmi,bmi2") using namespace std; using i32 = int; //#define int long long #define len(x) (int)(x.size()) #define inf 1000'000'000'000'000'000LL #define all(x) x.begin(), x.end() #define low_bit(x) (x & (-x)) template<typename T> using vec = vector<T>; const int maxM = 701; template<typename it> struct SparseTable { using T = typename remove_reference<decltype(*declval<it>())>::type; vector<vector<T>> t; function<T(T, T)> f; vector<int> log; SparseTable() = default; SparseTable(it first, it last, function<T(T, T)> op) : t(1), f(op) { int n = distance(first, last); t.assign(32 - __builtin_clz(n), vector<T>(n)); t[0].assign(first, last); // calc log log.resize(n + 1); for (int i = 2; i <= n; i++) log[i] = log[i / 2] + 1; for (int i = 1; i < t.size(); i++) for (int j = 0; j < n - (1 << i) + 1; j++) t[i][j] = f(t[i - 1][j], t[i - 1][j + (1 << (i - 1))]); } // returns f(a[l..r]) in O(1) time T get(int l, int r) { int h = log[r - l + 1]; return f(t[h][l], t[h][r - (1 << h) + 1]); } }; long long count_rectangles(std::vector<std::vector<i32>> a) { int n = len(a); int m = len(a[0]); long long ans = 0; vec<vec<bitset<maxM>>> b(n, vec<bitset<maxM>>(m)); for (int i = 1; i < n - 1; i++) { for (int j = 1; j < m - 1; j++) { b[i][j].reset(); int mx = a[i][j]; for (int l = i; l < n - 1; l++) { mx = max(mx, a[l][j]); if (mx >= min(a[i - 1][j], a[l + 1][j])) continue; b[i][j][l] = true; } } } vec<vec<bitset<maxM>>> good(m, vec<bitset<maxM>>(m)); vec<SparseTable<vec<int>::iterator>> maxVal; for (int i = 0; i < n; i++) { maxVal.emplace_back(all(a[i]), [](int a, int b) { return max(a, b); }); } for (int l = 1; l < m - 1; l++) { for (int r = l; r < m - 1; r++) { for (int i = 0; i < n; i++) { good[l][r][i] = maxVal[i].get(l, r) < min(a[i][l - 1], a[i][r + 1]); } } } vec<vec<vec<short>>> lowest(m, vec<vec<short>>(m, vec<short>(n, 0))); for (int l = 1; l < m - 1; l++) { for (int r = l; r < m - 1; r++) { for (int i = n - 2; i >= 1; i--) { if (!good[l][r][i]) continue; lowest[l][r][i] = lowest[l][r][i + 1] + 1; } } } for (int i = 1; i < n - 1; i++) { for (int j = 1; j < m - 1; j++) { if (a[i][j] >= a[i - 1][j]) continue; if (a[i][j] >= a[i][j - 1]) continue; for (int k = j; k < m - 1; k++) { b[i][j] &= b[i][k]; if (b[i][j].count() == 0) break; if (lowest[j][k][i] == 0) continue; ans += (b[i][j] & ((good[j][k] << (maxM - i - lowest[j][k][i])) >> (maxM - i - lowest[j][k][i]))).count(); } } } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 428 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 0 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 600 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 1 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 | 1 ms | 604 KB | Output is correct |
19 | Correct | 1 ms | 604 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 428 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 0 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 600 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 1 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 | 1 ms | 604 KB | Output is correct |
19 | Correct | 1 ms | 604 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 428 KB | Output is correct |
22 | Correct | 7 ms | 2908 KB | Output is correct |
23 | Correct | 7 ms | 2904 KB | Output is correct |
24 | Correct | 7 ms | 2908 KB | Output is correct |
25 | Correct | 4 ms | 2908 KB | Output is correct |
26 | Correct | 5 ms | 2860 KB | Output is correct |
27 | Correct | 4 ms | 2872 KB | Output is correct |
28 | Correct | 5 ms | 2904 KB | Output is correct |
29 | Correct | 2 ms | 1116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 428 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 0 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 600 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 1 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 | 7 ms | 2908 KB | Output is correct |
18 | Correct | 7 ms | 2904 KB | Output is correct |
19 | Correct | 7 ms | 2908 KB | Output is correct |
20 | Correct | 4 ms | 2908 KB | Output is correct |
21 | Correct | 5 ms | 2860 KB | Output is correct |
22 | Correct | 4 ms | 2872 KB | Output is correct |
23 | Correct | 5 ms | 2904 KB | Output is correct |
24 | Correct | 2 ms | 1116 KB | Output is correct |
25 | Correct | 0 ms | 348 KB | Output is correct |
26 | Correct | 1 ms | 604 KB | Output is correct |
27 | Correct | 1 ms | 604 KB | Output is correct |
28 | Correct | 1 ms | 348 KB | Output is correct |
29 | Correct | 0 ms | 428 KB | Output is correct |
30 | Correct | 98 ms | 26452 KB | Output is correct |
31 | Correct | 98 ms | 26448 KB | Output is correct |
32 | Correct | 94 ms | 26704 KB | Output is correct |
33 | Correct | 54 ms | 26448 KB | Output is correct |
34 | Correct | 59 ms | 26448 KB | Output is correct |
35 | Correct | 59 ms | 26704 KB | Output is correct |
36 | Correct | 62 ms | 26708 KB | Output is correct |
37 | Correct | 56 ms | 26192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 428 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 0 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 600 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 1 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 | 7 ms | 2908 KB | Output is correct |
18 | Correct | 7 ms | 2904 KB | Output is correct |
19 | Correct | 7 ms | 2908 KB | Output is correct |
20 | Correct | 4 ms | 2908 KB | Output is correct |
21 | Correct | 5 ms | 2860 KB | Output is correct |
22 | Correct | 4 ms | 2872 KB | Output is correct |
23 | Correct | 5 ms | 2904 KB | Output is correct |
24 | Correct | 2 ms | 1116 KB | Output is correct |
25 | Correct | 98 ms | 26452 KB | Output is correct |
26 | Correct | 98 ms | 26448 KB | Output is correct |
27 | Correct | 94 ms | 26704 KB | Output is correct |
28 | Correct | 54 ms | 26448 KB | Output is correct |
29 | Correct | 59 ms | 26448 KB | Output is correct |
30 | Correct | 59 ms | 26704 KB | Output is correct |
31 | Correct | 62 ms | 26708 KB | Output is correct |
32 | Correct | 56 ms | 26192 KB | Output is correct |
33 | Correct | 0 ms | 348 KB | Output is correct |
34 | Correct | 1 ms | 604 KB | Output is correct |
35 | Correct | 1 ms | 604 KB | Output is correct |
36 | Correct | 1 ms | 348 KB | Output is correct |
37 | Correct | 0 ms | 428 KB | Output is correct |
38 | Correct | 2949 ms | 799824 KB | Output is correct |
39 | Correct | 2934 ms | 799724 KB | Output is correct |
40 | Correct | 2801 ms | 799320 KB | Output is correct |
41 | Correct | 2836 ms | 799340 KB | Output is correct |
42 | Correct | 4826 ms | 799340 KB | Output is correct |
43 | Correct | 4631 ms | 798896 KB | Output is correct |
44 | Correct | 4745 ms | 801104 KB | Output is correct |
45 | Correct | 4305 ms | 758208 KB | Output is correct |
46 | Correct | 2812 ms | 798508 KB | Output is correct |
47 | Correct | 2861 ms | 798512 KB | Output is correct |
48 | Correct | 2975 ms | 799336 KB | Output is correct |
49 | Correct | 3042 ms | 801384 KB | Output is correct |
50 | Correct | 702 ms | 218080 KB | Output is correct |
51 | Correct | 1124 ms | 435384 KB | Output is correct |
52 | Correct | 3003 ms | 800312 KB | Output is correct |
53 | Correct | 2898 ms | 801360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 557 ms | 882556 KB | Output is correct |
2 | Correct | 417 ms | 636568 KB | Output is correct |
3 | Correct | 545 ms | 882324 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 543 ms | 882300 KB | Output is correct |
6 | Correct | 533 ms | 882504 KB | Output is correct |
7 | Correct | 546 ms | 882376 KB | Output is correct |
8 | Correct | 786 ms | 882440 KB | Output is correct |
9 | Correct | 540 ms | 882300 KB | Output is correct |
10 | Correct | 516 ms | 881528 KB | Output is correct |
11 | Correct | 473 ms | 882044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 428 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Execution timed out | 5086 ms | 883832 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 428 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 604 KB | Output is correct |
9 | Correct | 0 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 600 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 1 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 | 7 ms | 2908 KB | Output is correct |
18 | Correct | 7 ms | 2904 KB | Output is correct |
19 | Correct | 7 ms | 2908 KB | Output is correct |
20 | Correct | 4 ms | 2908 KB | Output is correct |
21 | Correct | 5 ms | 2860 KB | Output is correct |
22 | Correct | 4 ms | 2872 KB | Output is correct |
23 | Correct | 5 ms | 2904 KB | Output is correct |
24 | Correct | 2 ms | 1116 KB | Output is correct |
25 | Correct | 98 ms | 26452 KB | Output is correct |
26 | Correct | 98 ms | 26448 KB | Output is correct |
27 | Correct | 94 ms | 26704 KB | Output is correct |
28 | Correct | 54 ms | 26448 KB | Output is correct |
29 | Correct | 59 ms | 26448 KB | Output is correct |
30 | Correct | 59 ms | 26704 KB | Output is correct |
31 | Correct | 62 ms | 26708 KB | Output is correct |
32 | Correct | 56 ms | 26192 KB | Output is correct |
33 | Correct | 2949 ms | 799824 KB | Output is correct |
34 | Correct | 2934 ms | 799724 KB | Output is correct |
35 | Correct | 2801 ms | 799320 KB | Output is correct |
36 | Correct | 2836 ms | 799340 KB | Output is correct |
37 | Correct | 4826 ms | 799340 KB | Output is correct |
38 | Correct | 4631 ms | 798896 KB | Output is correct |
39 | Correct | 4745 ms | 801104 KB | Output is correct |
40 | Correct | 4305 ms | 758208 KB | Output is correct |
41 | Correct | 2812 ms | 798508 KB | Output is correct |
42 | Correct | 2861 ms | 798512 KB | Output is correct |
43 | Correct | 2975 ms | 799336 KB | Output is correct |
44 | Correct | 3042 ms | 801384 KB | Output is correct |
45 | Correct | 702 ms | 218080 KB | Output is correct |
46 | Correct | 1124 ms | 435384 KB | Output is correct |
47 | Correct | 3003 ms | 800312 KB | Output is correct |
48 | Correct | 2898 ms | 801360 KB | Output is correct |
49 | Correct | 557 ms | 882556 KB | Output is correct |
50 | Correct | 417 ms | 636568 KB | Output is correct |
51 | Correct | 545 ms | 882324 KB | Output is correct |
52 | Correct | 0 ms | 348 KB | Output is correct |
53 | Correct | 543 ms | 882300 KB | Output is correct |
54 | Correct | 533 ms | 882504 KB | Output is correct |
55 | Correct | 546 ms | 882376 KB | Output is correct |
56 | Correct | 786 ms | 882440 KB | Output is correct |
57 | Correct | 540 ms | 882300 KB | Output is correct |
58 | Correct | 516 ms | 881528 KB | Output is correct |
59 | Correct | 473 ms | 882044 KB | Output is correct |
60 | Correct | 0 ms | 348 KB | Output is correct |
61 | Execution timed out | 5086 ms | 883832 KB | Time limit exceeded |
62 | Halted | 0 ms | 0 KB | - |