# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
143633 |
2019-08-14T19:06:15 Z |
Kanon |
Rectangles (IOI19_rect) |
C++14 |
|
5000 ms |
736308 KB |
#include <bits/stdc++.h>
using namespace std;
#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)
struct sp {
vector<int> st;
unordered_set<int> alive;
sp(){};
void add(int ss) {
st.push_back(ss);
alive.insert(ss);
}
int pos(int ss) {
return upper_bound(st.begin(), st.end(), ss, greater<int>()) - st.begin();
}
sp operator ^ (const sp &a) const {
sp res;
for(auto i : (a.st.size() < st.size() ? a.st : st)) {
if((a.st.size() < st.size() ? alive : a.alive).count(i)) res.add(i);
}
return res;
}
};
long long count_rectangles(vector<vector<int>> a) {
int m = a.front().size();
int n = a.size();
auto pos = [&] (vector<int> cur) {
int s = cur.size();
vector<pair<int, int>> res;
vector<int> st;
range(i, 0, s) {
while(st.size() && cur[st.back()] <= cur[i]) {
if(st.back() < i - 1) res.emplace_back(st.back() + 1, i - 1);
int b = st.back();
st.pop_back();
if(cur[b] == cur[i]) goto A;
}
if(st.size() && st.back() < i - 1) res.emplace_back(st.back() + 1, i - 1);
A:;
st.push_back(i);
}
return res;
};
vector<vector<sp>> cur(n, vector<sp>(m));
range(i, 0, n) {
vector<pair<int, int>> ss = pos(a[i]);
for(auto j : ss) {
cur[i][j.second].add(j.first);
}
}
long long res = 0;
vector<vector<pair<int, int>>> to(n, vector<pair<int, int>> (n, make_pair(-2, -2)));
range(i, 0, m) {
vector<int> psy(n);
range(j, 0, n) psy[j] = a[j][i];
vector<pair<int, int>> ss = pos(psy);
int sz = ss.size();
vector<sp> dp(sz);
vector<int> pr(n, -1);
range(j, 0, sz) {
int p = ss[j].second;
dp[j] = cur[p][i];
while(p >= ss[j].first) {
if(~pr[p]) {
sp pp = dp[j] ^ dp[pr[p]];
swap(pp, dp[j]);
p = ss[pr[p]].first - 1;
} else {
sp pp = dp[j] ^ cur[p][i];
swap(pp, dp[j]);
p--;
}
}
pr[ss[j].second] = j;
int l = to[ss[j].first][ss[j].second].second == i - 1 ? to[ss[j].first][ss[j].second].first : i;
if(l == i) to[ss[j].first][ss[j].second] = make_pair(i, i);
to[ss[j].first][ss[j].second].second = i;
res += dp[j].pos(l);
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
404 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
404 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
7 ms |
1528 KB |
Output is correct |
18 |
Correct |
7 ms |
1528 KB |
Output is correct |
19 |
Correct |
8 ms |
1528 KB |
Output is correct |
20 |
Correct |
5 ms |
1144 KB |
Output is correct |
21 |
Correct |
8 ms |
1272 KB |
Output is correct |
22 |
Correct |
9 ms |
1272 KB |
Output is correct |
23 |
Correct |
9 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
888 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
404 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
7 ms |
1528 KB |
Output is correct |
18 |
Correct |
7 ms |
1528 KB |
Output is correct |
19 |
Correct |
8 ms |
1528 KB |
Output is correct |
20 |
Correct |
5 ms |
1144 KB |
Output is correct |
21 |
Correct |
8 ms |
1272 KB |
Output is correct |
22 |
Correct |
9 ms |
1272 KB |
Output is correct |
23 |
Correct |
9 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
888 KB |
Output is correct |
25 |
Correct |
42 ms |
8088 KB |
Output is correct |
26 |
Correct |
41 ms |
8044 KB |
Output is correct |
27 |
Correct |
41 ms |
8056 KB |
Output is correct |
28 |
Correct |
22 ms |
5496 KB |
Output is correct |
29 |
Correct |
61 ms |
6780 KB |
Output is correct |
30 |
Correct |
50 ms |
6776 KB |
Output is correct |
31 |
Correct |
48 ms |
6520 KB |
Output is correct |
32 |
Correct |
47 ms |
6528 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
404 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
7 ms |
1528 KB |
Output is correct |
18 |
Correct |
7 ms |
1528 KB |
Output is correct |
19 |
Correct |
8 ms |
1528 KB |
Output is correct |
20 |
Correct |
5 ms |
1144 KB |
Output is correct |
21 |
Correct |
8 ms |
1272 KB |
Output is correct |
22 |
Correct |
9 ms |
1272 KB |
Output is correct |
23 |
Correct |
9 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
888 KB |
Output is correct |
25 |
Correct |
42 ms |
8088 KB |
Output is correct |
26 |
Correct |
41 ms |
8044 KB |
Output is correct |
27 |
Correct |
41 ms |
8056 KB |
Output is correct |
28 |
Correct |
22 ms |
5496 KB |
Output is correct |
29 |
Correct |
61 ms |
6780 KB |
Output is correct |
30 |
Correct |
50 ms |
6776 KB |
Output is correct |
31 |
Correct |
48 ms |
6520 KB |
Output is correct |
32 |
Correct |
47 ms |
6528 KB |
Output is correct |
33 |
Execution timed out |
5020 ms |
58588 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1588 KB |
Output is correct |
2 |
Correct |
6 ms |
1360 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
1460 KB |
Output is correct |
6 |
Correct |
8 ms |
1588 KB |
Output is correct |
7 |
Correct |
6 ms |
1460 KB |
Output is correct |
8 |
Correct |
6 ms |
1460 KB |
Output is correct |
9 |
Correct |
6 ms |
1460 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
5 ms |
1076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
1291 ms |
329668 KB |
Output is correct |
3 |
Correct |
2852 ms |
732212 KB |
Output is correct |
4 |
Correct |
3023 ms |
736216 KB |
Output is correct |
5 |
Correct |
2873 ms |
736308 KB |
Output is correct |
6 |
Correct |
384 ms |
278984 KB |
Output is correct |
7 |
Correct |
787 ms |
556552 KB |
Output is correct |
8 |
Correct |
829 ms |
589492 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
404 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
7 ms |
1528 KB |
Output is correct |
18 |
Correct |
7 ms |
1528 KB |
Output is correct |
19 |
Correct |
8 ms |
1528 KB |
Output is correct |
20 |
Correct |
5 ms |
1144 KB |
Output is correct |
21 |
Correct |
8 ms |
1272 KB |
Output is correct |
22 |
Correct |
9 ms |
1272 KB |
Output is correct |
23 |
Correct |
9 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
888 KB |
Output is correct |
25 |
Correct |
42 ms |
8088 KB |
Output is correct |
26 |
Correct |
41 ms |
8044 KB |
Output is correct |
27 |
Correct |
41 ms |
8056 KB |
Output is correct |
28 |
Correct |
22 ms |
5496 KB |
Output is correct |
29 |
Correct |
61 ms |
6780 KB |
Output is correct |
30 |
Correct |
50 ms |
6776 KB |
Output is correct |
31 |
Correct |
48 ms |
6520 KB |
Output is correct |
32 |
Correct |
47 ms |
6528 KB |
Output is correct |
33 |
Execution timed out |
5020 ms |
58588 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |