# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
887975 | 2023-12-15T16:08:03 Z | abczz | Rectangles (IOI19_rect) | C++14 | 5000 ms | 685004 KB |
#include "rect.h" #include <iostream> #include <map> #include <algorithm> #include <array> #include <vector> #define ll long long using namespace std; map <ll, ll> mp; vector <ll> U; vector <array<ll, 2>> V; vector <array<ll, 2>> A[2500][2500], B[2500][2500]; ll bit[2501], n, m, f; void add(ll u) { while (u <= n) { U.push_back(u); ++bit[u]; u += u & -u; } } ll query(ll u) { ll res = 0; while (u) { res += bit[u]; u -= u & -u; } return res; } long long count_rectangles(std::vector<std::vector<int> > a) { n = a.size(), m = a[0].size(), f = 0; for (int i=0; i<n; ++i) { mp.clear(); V.clear(); for (int j=0; j<m; ++j) { V.push_back({a[i][j], j}); } sort(V.begin(), V.end(), [](auto a, auto b) { return a[0] > b[0]; }); ll p = 0; for (int j=0; j<V.size(); ++j) { mp[V[j][1]] = p; if (j != V.size()-1 && V[j][0] == V[j+1][0]) continue; else { while (p <= j) { auto it = mp.lower_bound(V[p][1]); if (it != mp.begin()) { auto pv = prev(it); if (pv->first+1 != it->first) { A[i][it->first-1].push_back({pv->first+1, i}); } } auto nx = next(it); if (nx != mp.end() && it->first+1 != nx->first && it->second != nx->second) { A[i][nx->first-1].push_back({it->first+1, i}); } ++p; } } } for (int j=0; j<m; ++j) { if (i && !A[i][j].empty()) { int k = 0; for (auto [u, v] : A[i-1][j]) { while (k < A[i][j].size()-1 && A[i][j][k][0] < u) ++k; if (A[i][j][k][0] == u) A[i][j][k][1] = v; } } } } for (int j=0; j<m; ++j) { mp.clear(); V.clear(); for (int i=0; i<n; ++i) { V.push_back({a[i][j], i}); } sort(V.begin(), V.end(), [](auto a, auto b) { return a[0] > b[0]; }); ll p = 0; for (int i=0; i<V.size(); ++i) { mp[V[i][1]] = p; if (i != V.size()-1 && V[i][0] == V[i+1][0]) continue; else { while (p <= i) { auto it = mp.lower_bound(V[p][1]); if (it != mp.begin()) { auto pv = prev(it); if (pv->first+1 != it->first) { B[it->first-1][j].push_back({j, pv->first+1}); } } auto nx = next(it); if (nx != mp.end() && it->first+1 != nx->first && it->second != nx->second) { B[nx->first-1][j].push_back({j, it->first+1}); } ++p; } } } for (int i=0; i<n; ++i) { if (j && !B[i][j].empty()) { int k = 0; for (auto [u, v] : B[i][j-1]) { while (k < B[i][j].size()-1 && B[i][j][k][1] < v) ++k; if (B[i][j][k][1] == v) B[i][j][k][0] = u; } } } } for (int i=0; i<n; ++i) { for (int j=0; j<m; ++j) { sort(B[i][j].begin(), B[i][j].end()); ll l = 0, r = 0; while (l < A[i][j].size() && r < B[i][j].size()) { if (B[i][j][r][0] <= A[i][j][l][0]) { //if (i == 4 && j == 3) cout << B[i][j][r][0] << "*" << B[i][j][r][1] << endl; add(n-B[i][j][r][1]); ++r; } else { f += query(n-A[i][j][l][1]); //if (i == 4 && j == 3) cout << A[i][j][l][0] << " " << A[i][j][l][1] << endl; /*if (query(n-A[i][j][l][1])) { cout << A[i][j][l][0] << " " << A[i][j][l][1] << endl; cout << i << " " << j << " " << query(n-A[i][j][l][1]) << '\n'; }*/ ++l; } } while (l < A[i][j].size()) { f += query(n-A[i][j][l][1]); /*if (query(n-A[i][j][l][1])) { cout << A[i][j][l][0] << " " << A[i][j][l][1] << endl; cout << i << " " << j << " " << query(n-A[i][j][l][1]) << '\n'; }*/ ++l; } while (!U.empty()) { auto u = U.back(); U.pop_back(); bit[u] = 0; } } } return f; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 293944 KB | Output is correct |
2 | Correct | 62 ms | 293972 KB | Output is correct |
3 | Correct | 63 ms | 293972 KB | Output is correct |
4 | Correct | 63 ms | 293900 KB | Output is correct |
5 | Correct | 68 ms | 293968 KB | Output is correct |
6 | Correct | 63 ms | 293968 KB | Output is correct |
7 | Correct | 63 ms | 293968 KB | Output is correct |
8 | Correct | 65 ms | 293968 KB | Output is correct |
9 | Correct | 63 ms | 293968 KB | Output is correct |
10 | Correct | 63 ms | 293972 KB | Output is correct |
11 | Correct | 64 ms | 293972 KB | Output is correct |
12 | Correct | 63 ms | 293972 KB | Output is correct |
13 | Correct | 62 ms | 293712 KB | Output is correct |
14 | Correct | 62 ms | 293908 KB | Output is correct |
15 | Correct | 63 ms | 293716 KB | Output is correct |
16 | Correct | 62 ms | 293716 KB | Output is correct |
17 | Correct | 66 ms | 294072 KB | Output is correct |
18 | Correct | 62 ms | 293716 KB | Output is correct |
19 | Correct | 64 ms | 293768 KB | Output is correct |
20 | Correct | 62 ms | 293716 KB | Output is correct |
21 | Correct | 63 ms | 293820 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 293944 KB | Output is correct |
2 | Correct | 62 ms | 293972 KB | Output is correct |
3 | Correct | 63 ms | 293972 KB | Output is correct |
4 | Correct | 63 ms | 293900 KB | Output is correct |
5 | Correct | 68 ms | 293968 KB | Output is correct |
6 | Correct | 63 ms | 293968 KB | Output is correct |
7 | Correct | 63 ms | 293968 KB | Output is correct |
8 | Correct | 65 ms | 293968 KB | Output is correct |
9 | Correct | 63 ms | 293968 KB | Output is correct |
10 | Correct | 63 ms | 293972 KB | Output is correct |
11 | Correct | 64 ms | 293972 KB | Output is correct |
12 | Correct | 63 ms | 293972 KB | Output is correct |
13 | Correct | 62 ms | 293712 KB | Output is correct |
14 | Correct | 62 ms | 293908 KB | Output is correct |
15 | Correct | 63 ms | 293716 KB | Output is correct |
16 | Correct | 62 ms | 293716 KB | Output is correct |
17 | Correct | 66 ms | 294072 KB | Output is correct |
18 | Correct | 62 ms | 293716 KB | Output is correct |
19 | Correct | 64 ms | 293768 KB | Output is correct |
20 | Correct | 62 ms | 293716 KB | Output is correct |
21 | Correct | 63 ms | 293820 KB | Output is correct |
22 | Correct | 65 ms | 294276 KB | Output is correct |
23 | Correct | 66 ms | 294228 KB | Output is correct |
24 | Correct | 65 ms | 294308 KB | Output is correct |
25 | Correct | 64 ms | 293976 KB | Output is correct |
26 | Correct | 67 ms | 294224 KB | Output is correct |
27 | Correct | 70 ms | 294320 KB | Output is correct |
28 | Correct | 66 ms | 294228 KB | Output is correct |
29 | Correct | 64 ms | 294068 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 293944 KB | Output is correct |
2 | Correct | 62 ms | 293972 KB | Output is correct |
3 | Correct | 63 ms | 293972 KB | Output is correct |
4 | Correct | 63 ms | 293900 KB | Output is correct |
5 | Correct | 68 ms | 293968 KB | Output is correct |
6 | Correct | 63 ms | 293968 KB | Output is correct |
7 | Correct | 63 ms | 293968 KB | Output is correct |
8 | Correct | 65 ms | 293968 KB | Output is correct |
9 | Correct | 63 ms | 293968 KB | Output is correct |
10 | Correct | 63 ms | 293972 KB | Output is correct |
11 | Correct | 64 ms | 293972 KB | Output is correct |
12 | Correct | 63 ms | 293972 KB | Output is correct |
13 | Correct | 62 ms | 293712 KB | Output is correct |
14 | Correct | 62 ms | 293908 KB | Output is correct |
15 | Correct | 63 ms | 293716 KB | Output is correct |
16 | Correct | 62 ms | 293716 KB | Output is correct |
17 | Correct | 65 ms | 294276 KB | Output is correct |
18 | Correct | 66 ms | 294228 KB | Output is correct |
19 | Correct | 65 ms | 294308 KB | Output is correct |
20 | Correct | 64 ms | 293976 KB | Output is correct |
21 | Correct | 67 ms | 294224 KB | Output is correct |
22 | Correct | 70 ms | 294320 KB | Output is correct |
23 | Correct | 66 ms | 294228 KB | Output is correct |
24 | Correct | 64 ms | 294068 KB | Output is correct |
25 | Correct | 66 ms | 294072 KB | Output is correct |
26 | Correct | 62 ms | 293716 KB | Output is correct |
27 | Correct | 64 ms | 293768 KB | Output is correct |
28 | Correct | 62 ms | 293716 KB | Output is correct |
29 | Correct | 63 ms | 293820 KB | Output is correct |
30 | Correct | 77 ms | 296140 KB | Output is correct |
31 | Correct | 76 ms | 296020 KB | Output is correct |
32 | Correct | 75 ms | 296020 KB | Output is correct |
33 | Correct | 81 ms | 295160 KB | Output is correct |
34 | Correct | 87 ms | 296168 KB | Output is correct |
35 | Correct | 97 ms | 296548 KB | Output is correct |
36 | Correct | 86 ms | 296272 KB | Output is correct |
37 | Correct | 86 ms | 296276 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 293944 KB | Output is correct |
2 | Correct | 62 ms | 293972 KB | Output is correct |
3 | Correct | 63 ms | 293972 KB | Output is correct |
4 | Correct | 63 ms | 293900 KB | Output is correct |
5 | Correct | 68 ms | 293968 KB | Output is correct |
6 | Correct | 63 ms | 293968 KB | Output is correct |
7 | Correct | 63 ms | 293968 KB | Output is correct |
8 | Correct | 65 ms | 293968 KB | Output is correct |
9 | Correct | 63 ms | 293968 KB | Output is correct |
10 | Correct | 63 ms | 293972 KB | Output is correct |
11 | Correct | 64 ms | 293972 KB | Output is correct |
12 | Correct | 63 ms | 293972 KB | Output is correct |
13 | Correct | 62 ms | 293712 KB | Output is correct |
14 | Correct | 62 ms | 293908 KB | Output is correct |
15 | Correct | 63 ms | 293716 KB | Output is correct |
16 | Correct | 62 ms | 293716 KB | Output is correct |
17 | Correct | 65 ms | 294276 KB | Output is correct |
18 | Correct | 66 ms | 294228 KB | Output is correct |
19 | Correct | 65 ms | 294308 KB | Output is correct |
20 | Correct | 64 ms | 293976 KB | Output is correct |
21 | Correct | 67 ms | 294224 KB | Output is correct |
22 | Correct | 70 ms | 294320 KB | Output is correct |
23 | Correct | 66 ms | 294228 KB | Output is correct |
24 | Correct | 64 ms | 294068 KB | Output is correct |
25 | Correct | 77 ms | 296140 KB | Output is correct |
26 | Correct | 76 ms | 296020 KB | Output is correct |
27 | Correct | 75 ms | 296020 KB | Output is correct |
28 | Correct | 81 ms | 295160 KB | Output is correct |
29 | Correct | 87 ms | 296168 KB | Output is correct |
30 | Correct | 97 ms | 296548 KB | Output is correct |
31 | Correct | 86 ms | 296272 KB | Output is correct |
32 | Correct | 86 ms | 296276 KB | Output is correct |
33 | Correct | 66 ms | 294072 KB | Output is correct |
34 | Correct | 62 ms | 293716 KB | Output is correct |
35 | Correct | 64 ms | 293768 KB | Output is correct |
36 | Correct | 62 ms | 293716 KB | Output is correct |
37 | Correct | 63 ms | 293820 KB | Output is correct |
38 | Correct | 225 ms | 311324 KB | Output is correct |
39 | Correct | 234 ms | 313556 KB | Output is correct |
40 | Correct | 239 ms | 313676 KB | Output is correct |
41 | Correct | 233 ms | 316180 KB | Output is correct |
42 | Correct | 261 ms | 321904 KB | Output is correct |
43 | Correct | 237 ms | 321872 KB | Output is correct |
44 | Correct | 251 ms | 322128 KB | Output is correct |
45 | Correct | 229 ms | 320596 KB | Output is correct |
46 | Correct | 285 ms | 306328 KB | Output is correct |
47 | Correct | 311 ms | 309888 KB | Output is correct |
48 | Correct | 409 ms | 324096 KB | Output is correct |
49 | Correct | 414 ms | 326228 KB | Output is correct |
50 | Correct | 227 ms | 310008 KB | Output is correct |
51 | Correct | 224 ms | 310100 KB | Output is correct |
52 | Correct | 405 ms | 323412 KB | Output is correct |
53 | Correct | 402 ms | 324348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 294188 KB | Output is correct |
2 | Correct | 65 ms | 294224 KB | Output is correct |
3 | Correct | 69 ms | 294076 KB | Output is correct |
4 | Correct | 63 ms | 293712 KB | Output is correct |
5 | Correct | 66 ms | 294332 KB | Output is correct |
6 | Correct | 75 ms | 294224 KB | Output is correct |
7 | Correct | 65 ms | 294228 KB | Output is correct |
8 | Correct | 65 ms | 294316 KB | Output is correct |
9 | Correct | 66 ms | 294232 KB | Output is correct |
10 | Correct | 65 ms | 294224 KB | Output is correct |
11 | Correct | 65 ms | 294224 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 294072 KB | Output is correct |
2 | Correct | 62 ms | 293716 KB | Output is correct |
3 | Correct | 64 ms | 293768 KB | Output is correct |
4 | Correct | 62 ms | 293716 KB | Output is correct |
5 | Correct | 63 ms | 293820 KB | Output is correct |
6 | Correct | 62 ms | 293720 KB | Output is correct |
7 | Correct | 1522 ms | 361244 KB | Output is correct |
8 | Correct | 3318 ms | 440068 KB | Output is correct |
9 | Correct | 3287 ms | 440684 KB | Output is correct |
10 | Correct | 3391 ms | 441168 KB | Output is correct |
11 | Correct | 1128 ms | 318404 KB | Output is correct |
12 | Correct | 2157 ms | 340324 KB | Output is correct |
13 | Correct | 2263 ms | 343380 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 293944 KB | Output is correct |
2 | Correct | 62 ms | 293972 KB | Output is correct |
3 | Correct | 63 ms | 293972 KB | Output is correct |
4 | Correct | 63 ms | 293900 KB | Output is correct |
5 | Correct | 68 ms | 293968 KB | Output is correct |
6 | Correct | 63 ms | 293968 KB | Output is correct |
7 | Correct | 63 ms | 293968 KB | Output is correct |
8 | Correct | 65 ms | 293968 KB | Output is correct |
9 | Correct | 63 ms | 293968 KB | Output is correct |
10 | Correct | 63 ms | 293972 KB | Output is correct |
11 | Correct | 64 ms | 293972 KB | Output is correct |
12 | Correct | 63 ms | 293972 KB | Output is correct |
13 | Correct | 62 ms | 293712 KB | Output is correct |
14 | Correct | 62 ms | 293908 KB | Output is correct |
15 | Correct | 63 ms | 293716 KB | Output is correct |
16 | Correct | 62 ms | 293716 KB | Output is correct |
17 | Correct | 65 ms | 294276 KB | Output is correct |
18 | Correct | 66 ms | 294228 KB | Output is correct |
19 | Correct | 65 ms | 294308 KB | Output is correct |
20 | Correct | 64 ms | 293976 KB | Output is correct |
21 | Correct | 67 ms | 294224 KB | Output is correct |
22 | Correct | 70 ms | 294320 KB | Output is correct |
23 | Correct | 66 ms | 294228 KB | Output is correct |
24 | Correct | 64 ms | 294068 KB | Output is correct |
25 | Correct | 77 ms | 296140 KB | Output is correct |
26 | Correct | 76 ms | 296020 KB | Output is correct |
27 | Correct | 75 ms | 296020 KB | Output is correct |
28 | Correct | 81 ms | 295160 KB | Output is correct |
29 | Correct | 87 ms | 296168 KB | Output is correct |
30 | Correct | 97 ms | 296548 KB | Output is correct |
31 | Correct | 86 ms | 296272 KB | Output is correct |
32 | Correct | 86 ms | 296276 KB | Output is correct |
33 | Correct | 225 ms | 311324 KB | Output is correct |
34 | Correct | 234 ms | 313556 KB | Output is correct |
35 | Correct | 239 ms | 313676 KB | Output is correct |
36 | Correct | 233 ms | 316180 KB | Output is correct |
37 | Correct | 261 ms | 321904 KB | Output is correct |
38 | Correct | 237 ms | 321872 KB | Output is correct |
39 | Correct | 251 ms | 322128 KB | Output is correct |
40 | Correct | 229 ms | 320596 KB | Output is correct |
41 | Correct | 285 ms | 306328 KB | Output is correct |
42 | Correct | 311 ms | 309888 KB | Output is correct |
43 | Correct | 409 ms | 324096 KB | Output is correct |
44 | Correct | 414 ms | 326228 KB | Output is correct |
45 | Correct | 227 ms | 310008 KB | Output is correct |
46 | Correct | 224 ms | 310100 KB | Output is correct |
47 | Correct | 405 ms | 323412 KB | Output is correct |
48 | Correct | 402 ms | 324348 KB | Output is correct |
49 | Correct | 69 ms | 294188 KB | Output is correct |
50 | Correct | 65 ms | 294224 KB | Output is correct |
51 | Correct | 69 ms | 294076 KB | Output is correct |
52 | Correct | 63 ms | 293712 KB | Output is correct |
53 | Correct | 66 ms | 294332 KB | Output is correct |
54 | Correct | 75 ms | 294224 KB | Output is correct |
55 | Correct | 65 ms | 294228 KB | Output is correct |
56 | Correct | 65 ms | 294316 KB | Output is correct |
57 | Correct | 66 ms | 294232 KB | Output is correct |
58 | Correct | 65 ms | 294224 KB | Output is correct |
59 | Correct | 65 ms | 294224 KB | Output is correct |
60 | Correct | 62 ms | 293720 KB | Output is correct |
61 | Correct | 1522 ms | 361244 KB | Output is correct |
62 | Correct | 3318 ms | 440068 KB | Output is correct |
63 | Correct | 3287 ms | 440684 KB | Output is correct |
64 | Correct | 3391 ms | 441168 KB | Output is correct |
65 | Correct | 1128 ms | 318404 KB | Output is correct |
66 | Correct | 2157 ms | 340324 KB | Output is correct |
67 | Correct | 2263 ms | 343380 KB | Output is correct |
68 | Correct | 66 ms | 294072 KB | Output is correct |
69 | Correct | 62 ms | 293716 KB | Output is correct |
70 | Correct | 64 ms | 293768 KB | Output is correct |
71 | Correct | 62 ms | 293716 KB | Output is correct |
72 | Correct | 63 ms | 293820 KB | Output is correct |
73 | Correct | 2284 ms | 503264 KB | Output is correct |
74 | Correct | 2442 ms | 547164 KB | Output is correct |
75 | Correct | 2496 ms | 541736 KB | Output is correct |
76 | Correct | 2843 ms | 585432 KB | Output is correct |
77 | Correct | 2603 ms | 607376 KB | Output is correct |
78 | Correct | 3315 ms | 527808 KB | Output is correct |
79 | Correct | 3630 ms | 550768 KB | Output is correct |
80 | Execution timed out | 5100 ms | 685004 KB | Time limit exceeded |
81 | Halted | 0 ms | 0 KB | - |