# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1064900 |
2024-08-18T19:10:47 Z |
jerzyk |
Rectangles (IOI19_rect) |
C++17 |
|
4712 ms |
722336 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 2500 + 7;
int tab[N][N];
vector<int> intr[N][N];
vector<pair<int, int>> que[N][N];
bool czy[N];
long long answer = 0;
void CntR(int n, int m)
{
for(int i = 1; i <= n; ++i)
{
vector<pair<int, int>> kol;
for(int j = m; j >= 1; --j)
{
while((int)kol.size() > 0 && kol.back().st <= tab[i][j])
kol.pop_back();
int xd = tab[i][j];
//cerr << "R: " << i << " " << j << "\n";
for(int k = kol.size() - 1; k >= 0 && tab[i][j - 1] > xd; --k)
{
intr[i][j].pb(kol[k].nd - 1);
//cerr << kol[k].nd - 1 << " ";
xd = max(xd, kol[k].st);
}
//cout << "\n";
kol.pb(make_pair(tab[i][j], j));
}
}
for(int j = 1; j <= m; ++j)
{
vector<pair<int, int>> akt;
for(int i = j; i <= m; ++i)
akt.pb(make_pair(i, 1));
for(int i = 1; i <= n; ++i)
{
vector<pair<int, int>> nxt;
int k = 0;
//cerr << "DP: " << i << " " << j << "\n";
for(int l = 0; l < (int)intr[i][j].size(); ++l)
{
while(k < (int)akt.size() && akt[k].st < intr[i][j][l])
++k;
if(k < (int)akt.size() && akt[k].st == intr[i][j][l])
{
nxt.pb(akt[k]);
++k;
}else
nxt.pb(make_pair(intr[i][j][l], i));
que[i][intr[i][j][l]].pb(make_pair(j, i - nxt.back().nd + 1));
//cerr << nxt.back().st << " " << nxt.back().nd << "\n";
}
akt = nxt;
intr[i][j].clear();
}
}
}
void CntL(int n, int m)
{
for(int j = 1; j <= m; ++j)
{
vector<pair<int, int>> kol;
for(int i = 1; i <= n; ++i)
{
while((int)kol.size() > 0 && kol.back().st <= tab[i][j])
kol.pop_back();
int xd = tab[i][j];
//cerr << "U: " << i << " " << j << "\n";
for(int k = kol.size() - 1; k >= 0 && tab[i + 1][j] > xd; --k)
{
intr[i][j].pb(kol[k].nd + 1);
//cerr << kol[k].nd + 1 << "\n";
xd = max(xd, kol[k].st);
}
sort(intr[i][j].begin(), intr[i][j].end());
kol.pb(make_pair(tab[i][j], i));
}
}
for(int i = 1; i <= n; ++i)
{
vector<pair<int, int>> akt;
for(int j = i; j <= n; ++j)
akt.pb(make_pair(j, 1));
for(int j = 1; j <= m; ++j)
{
vector<pair<int, int>> nxt;
int k = 0;
//cerr << "DP: " << i << " " << j << "\n";
for(int l = 0; l < (int)intr[i][j].size(); ++l)
{
while(k < (int)akt.size() && akt[k].st < intr[i][j][l])
++k;
if(k < (int)akt.size() && akt[k].st == intr[i][j][l])
{
nxt.pb(make_pair(akt[k].nd, akt[k].st));
++k;
}else
nxt.pb(make_pair(j, intr[i][j][l]));
//cerr << nxt.back().nd << " " << nxt.back().st << "\n";
}
akt = nxt;
sort(akt.begin(), akt.end());
int lim = akt.size();
//cout << "QUE: " << i << " " << j << "\n";
for(int l = 0; l < (int)que[i][j].size(); ++l)
{
//cout << que[i][j][l].st << " " << que[i][j][l].nd << "\n";
for(int r = 0; r < lim; ++r)
if(akt[r].st <= que[i][j][l].st && i - akt[r].nd + 1 <= que[i][j][l].nd)
++answer;
}
for(int l = 0; l < (int)akt.size(); ++l)
swap(akt[l].st, akt[l].nd);
sort(akt.begin(), akt.end());
intr[i][j].clear();
}
}
}
long long count_rectangles(vector<vector<int>> xd)
{
int n = xd.size(), m = xd[0].size();
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
tab[i][j] = xd[i - 1][j - 1];
CntR(n, m);
CntL(n, m);
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
295508 KB |
Output is correct |
2 |
Correct |
118 ms |
295576 KB |
Output is correct |
3 |
Correct |
108 ms |
295768 KB |
Output is correct |
4 |
Correct |
114 ms |
295704 KB |
Output is correct |
5 |
Correct |
108 ms |
295504 KB |
Output is correct |
6 |
Correct |
115 ms |
295652 KB |
Output is correct |
7 |
Correct |
118 ms |
295508 KB |
Output is correct |
8 |
Correct |
116 ms |
295508 KB |
Output is correct |
9 |
Correct |
105 ms |
295760 KB |
Output is correct |
10 |
Correct |
113 ms |
295556 KB |
Output is correct |
11 |
Correct |
115 ms |
295720 KB |
Output is correct |
12 |
Correct |
116 ms |
295696 KB |
Output is correct |
13 |
Correct |
108 ms |
295508 KB |
Output is correct |
14 |
Correct |
118 ms |
295504 KB |
Output is correct |
15 |
Correct |
112 ms |
295504 KB |
Output is correct |
16 |
Correct |
109 ms |
295616 KB |
Output is correct |
17 |
Correct |
104 ms |
295504 KB |
Output is correct |
18 |
Correct |
110 ms |
295524 KB |
Output is correct |
19 |
Correct |
112 ms |
295760 KB |
Output is correct |
20 |
Correct |
117 ms |
295508 KB |
Output is correct |
21 |
Correct |
124 ms |
295576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
295508 KB |
Output is correct |
2 |
Correct |
118 ms |
295576 KB |
Output is correct |
3 |
Correct |
108 ms |
295768 KB |
Output is correct |
4 |
Correct |
114 ms |
295704 KB |
Output is correct |
5 |
Correct |
108 ms |
295504 KB |
Output is correct |
6 |
Correct |
115 ms |
295652 KB |
Output is correct |
7 |
Correct |
118 ms |
295508 KB |
Output is correct |
8 |
Correct |
116 ms |
295508 KB |
Output is correct |
9 |
Correct |
105 ms |
295760 KB |
Output is correct |
10 |
Correct |
113 ms |
295556 KB |
Output is correct |
11 |
Correct |
115 ms |
295720 KB |
Output is correct |
12 |
Correct |
116 ms |
295696 KB |
Output is correct |
13 |
Correct |
108 ms |
295508 KB |
Output is correct |
14 |
Correct |
118 ms |
295504 KB |
Output is correct |
15 |
Correct |
112 ms |
295504 KB |
Output is correct |
16 |
Correct |
109 ms |
295616 KB |
Output is correct |
17 |
Correct |
104 ms |
295504 KB |
Output is correct |
18 |
Correct |
110 ms |
295524 KB |
Output is correct |
19 |
Correct |
112 ms |
295760 KB |
Output is correct |
20 |
Correct |
117 ms |
295508 KB |
Output is correct |
21 |
Correct |
124 ms |
295576 KB |
Output is correct |
22 |
Correct |
119 ms |
296296 KB |
Output is correct |
23 |
Correct |
118 ms |
296204 KB |
Output is correct |
24 |
Correct |
109 ms |
296276 KB |
Output is correct |
25 |
Correct |
114 ms |
296016 KB |
Output is correct |
26 |
Correct |
107 ms |
296072 KB |
Output is correct |
27 |
Correct |
116 ms |
296276 KB |
Output is correct |
28 |
Correct |
132 ms |
296072 KB |
Output is correct |
29 |
Correct |
104 ms |
295888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
295508 KB |
Output is correct |
2 |
Correct |
118 ms |
295576 KB |
Output is correct |
3 |
Correct |
108 ms |
295768 KB |
Output is correct |
4 |
Correct |
114 ms |
295704 KB |
Output is correct |
5 |
Correct |
108 ms |
295504 KB |
Output is correct |
6 |
Correct |
115 ms |
295652 KB |
Output is correct |
7 |
Correct |
118 ms |
295508 KB |
Output is correct |
8 |
Correct |
116 ms |
295508 KB |
Output is correct |
9 |
Correct |
105 ms |
295760 KB |
Output is correct |
10 |
Correct |
113 ms |
295556 KB |
Output is correct |
11 |
Correct |
115 ms |
295720 KB |
Output is correct |
12 |
Correct |
116 ms |
295696 KB |
Output is correct |
13 |
Correct |
108 ms |
295508 KB |
Output is correct |
14 |
Correct |
118 ms |
295504 KB |
Output is correct |
15 |
Correct |
112 ms |
295504 KB |
Output is correct |
16 |
Correct |
109 ms |
295616 KB |
Output is correct |
17 |
Correct |
119 ms |
296296 KB |
Output is correct |
18 |
Correct |
118 ms |
296204 KB |
Output is correct |
19 |
Correct |
109 ms |
296276 KB |
Output is correct |
20 |
Correct |
114 ms |
296016 KB |
Output is correct |
21 |
Correct |
107 ms |
296072 KB |
Output is correct |
22 |
Correct |
116 ms |
296276 KB |
Output is correct |
23 |
Correct |
132 ms |
296072 KB |
Output is correct |
24 |
Correct |
104 ms |
295888 KB |
Output is correct |
25 |
Correct |
104 ms |
295504 KB |
Output is correct |
26 |
Correct |
110 ms |
295524 KB |
Output is correct |
27 |
Correct |
112 ms |
295760 KB |
Output is correct |
28 |
Correct |
117 ms |
295508 KB |
Output is correct |
29 |
Correct |
124 ms |
295576 KB |
Output is correct |
30 |
Correct |
118 ms |
298928 KB |
Output is correct |
31 |
Correct |
116 ms |
298836 KB |
Output is correct |
32 |
Correct |
111 ms |
299012 KB |
Output is correct |
33 |
Correct |
131 ms |
297812 KB |
Output is correct |
34 |
Correct |
120 ms |
298564 KB |
Output is correct |
35 |
Correct |
126 ms |
298832 KB |
Output is correct |
36 |
Correct |
126 ms |
298580 KB |
Output is correct |
37 |
Correct |
115 ms |
298580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
295508 KB |
Output is correct |
2 |
Correct |
118 ms |
295576 KB |
Output is correct |
3 |
Correct |
108 ms |
295768 KB |
Output is correct |
4 |
Correct |
114 ms |
295704 KB |
Output is correct |
5 |
Correct |
108 ms |
295504 KB |
Output is correct |
6 |
Correct |
115 ms |
295652 KB |
Output is correct |
7 |
Correct |
118 ms |
295508 KB |
Output is correct |
8 |
Correct |
116 ms |
295508 KB |
Output is correct |
9 |
Correct |
105 ms |
295760 KB |
Output is correct |
10 |
Correct |
113 ms |
295556 KB |
Output is correct |
11 |
Correct |
115 ms |
295720 KB |
Output is correct |
12 |
Correct |
116 ms |
295696 KB |
Output is correct |
13 |
Correct |
108 ms |
295508 KB |
Output is correct |
14 |
Correct |
118 ms |
295504 KB |
Output is correct |
15 |
Correct |
112 ms |
295504 KB |
Output is correct |
16 |
Correct |
109 ms |
295616 KB |
Output is correct |
17 |
Correct |
119 ms |
296296 KB |
Output is correct |
18 |
Correct |
118 ms |
296204 KB |
Output is correct |
19 |
Correct |
109 ms |
296276 KB |
Output is correct |
20 |
Correct |
114 ms |
296016 KB |
Output is correct |
21 |
Correct |
107 ms |
296072 KB |
Output is correct |
22 |
Correct |
116 ms |
296276 KB |
Output is correct |
23 |
Correct |
132 ms |
296072 KB |
Output is correct |
24 |
Correct |
104 ms |
295888 KB |
Output is correct |
25 |
Correct |
118 ms |
298928 KB |
Output is correct |
26 |
Correct |
116 ms |
298836 KB |
Output is correct |
27 |
Correct |
111 ms |
299012 KB |
Output is correct |
28 |
Correct |
131 ms |
297812 KB |
Output is correct |
29 |
Correct |
120 ms |
298564 KB |
Output is correct |
30 |
Correct |
126 ms |
298832 KB |
Output is correct |
31 |
Correct |
126 ms |
298580 KB |
Output is correct |
32 |
Correct |
115 ms |
298580 KB |
Output is correct |
33 |
Correct |
104 ms |
295504 KB |
Output is correct |
34 |
Correct |
110 ms |
295524 KB |
Output is correct |
35 |
Correct |
112 ms |
295760 KB |
Output is correct |
36 |
Correct |
117 ms |
295508 KB |
Output is correct |
37 |
Correct |
124 ms |
295576 KB |
Output is correct |
38 |
Correct |
244 ms |
319316 KB |
Output is correct |
39 |
Correct |
172 ms |
316244 KB |
Output is correct |
40 |
Correct |
184 ms |
325300 KB |
Output is correct |
41 |
Correct |
175 ms |
323920 KB |
Output is correct |
42 |
Correct |
205 ms |
331020 KB |
Output is correct |
43 |
Correct |
204 ms |
331088 KB |
Output is correct |
44 |
Correct |
196 ms |
331344 KB |
Output is correct |
45 |
Correct |
184 ms |
329276 KB |
Output is correct |
46 |
Correct |
177 ms |
314704 KB |
Output is correct |
47 |
Correct |
210 ms |
317520 KB |
Output is correct |
48 |
Correct |
263 ms |
325444 KB |
Output is correct |
49 |
Correct |
292 ms |
327508 KB |
Output is correct |
50 |
Correct |
211 ms |
312912 KB |
Output is correct |
51 |
Correct |
194 ms |
311416 KB |
Output is correct |
52 |
Correct |
255 ms |
324948 KB |
Output is correct |
53 |
Correct |
261 ms |
325972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
296020 KB |
Output is correct |
2 |
Correct |
134 ms |
296020 KB |
Output is correct |
3 |
Correct |
139 ms |
295684 KB |
Output is correct |
4 |
Correct |
119 ms |
295504 KB |
Output is correct |
5 |
Correct |
136 ms |
295792 KB |
Output is correct |
6 |
Correct |
133 ms |
295764 KB |
Output is correct |
7 |
Correct |
134 ms |
296000 KB |
Output is correct |
8 |
Correct |
142 ms |
295764 KB |
Output is correct |
9 |
Correct |
132 ms |
295832 KB |
Output is correct |
10 |
Correct |
135 ms |
295508 KB |
Output is correct |
11 |
Correct |
134 ms |
295764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
295504 KB |
Output is correct |
2 |
Correct |
110 ms |
295524 KB |
Output is correct |
3 |
Correct |
112 ms |
295760 KB |
Output is correct |
4 |
Correct |
117 ms |
295508 KB |
Output is correct |
5 |
Correct |
124 ms |
295576 KB |
Output is correct |
6 |
Correct |
116 ms |
295752 KB |
Output is correct |
7 |
Correct |
604 ms |
391808 KB |
Output is correct |
8 |
Correct |
1257 ms |
502760 KB |
Output is correct |
9 |
Correct |
1239 ms |
503632 KB |
Output is correct |
10 |
Correct |
1238 ms |
503624 KB |
Output is correct |
11 |
Correct |
257 ms |
338000 KB |
Output is correct |
12 |
Correct |
453 ms |
377556 KB |
Output is correct |
13 |
Correct |
475 ms |
381264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
295508 KB |
Output is correct |
2 |
Correct |
118 ms |
295576 KB |
Output is correct |
3 |
Correct |
108 ms |
295768 KB |
Output is correct |
4 |
Correct |
114 ms |
295704 KB |
Output is correct |
5 |
Correct |
108 ms |
295504 KB |
Output is correct |
6 |
Correct |
115 ms |
295652 KB |
Output is correct |
7 |
Correct |
118 ms |
295508 KB |
Output is correct |
8 |
Correct |
116 ms |
295508 KB |
Output is correct |
9 |
Correct |
105 ms |
295760 KB |
Output is correct |
10 |
Correct |
113 ms |
295556 KB |
Output is correct |
11 |
Correct |
115 ms |
295720 KB |
Output is correct |
12 |
Correct |
116 ms |
295696 KB |
Output is correct |
13 |
Correct |
108 ms |
295508 KB |
Output is correct |
14 |
Correct |
118 ms |
295504 KB |
Output is correct |
15 |
Correct |
112 ms |
295504 KB |
Output is correct |
16 |
Correct |
109 ms |
295616 KB |
Output is correct |
17 |
Correct |
119 ms |
296296 KB |
Output is correct |
18 |
Correct |
118 ms |
296204 KB |
Output is correct |
19 |
Correct |
109 ms |
296276 KB |
Output is correct |
20 |
Correct |
114 ms |
296016 KB |
Output is correct |
21 |
Correct |
107 ms |
296072 KB |
Output is correct |
22 |
Correct |
116 ms |
296276 KB |
Output is correct |
23 |
Correct |
132 ms |
296072 KB |
Output is correct |
24 |
Correct |
104 ms |
295888 KB |
Output is correct |
25 |
Correct |
118 ms |
298928 KB |
Output is correct |
26 |
Correct |
116 ms |
298836 KB |
Output is correct |
27 |
Correct |
111 ms |
299012 KB |
Output is correct |
28 |
Correct |
131 ms |
297812 KB |
Output is correct |
29 |
Correct |
120 ms |
298564 KB |
Output is correct |
30 |
Correct |
126 ms |
298832 KB |
Output is correct |
31 |
Correct |
126 ms |
298580 KB |
Output is correct |
32 |
Correct |
115 ms |
298580 KB |
Output is correct |
33 |
Correct |
244 ms |
319316 KB |
Output is correct |
34 |
Correct |
172 ms |
316244 KB |
Output is correct |
35 |
Correct |
184 ms |
325300 KB |
Output is correct |
36 |
Correct |
175 ms |
323920 KB |
Output is correct |
37 |
Correct |
205 ms |
331020 KB |
Output is correct |
38 |
Correct |
204 ms |
331088 KB |
Output is correct |
39 |
Correct |
196 ms |
331344 KB |
Output is correct |
40 |
Correct |
184 ms |
329276 KB |
Output is correct |
41 |
Correct |
177 ms |
314704 KB |
Output is correct |
42 |
Correct |
210 ms |
317520 KB |
Output is correct |
43 |
Correct |
263 ms |
325444 KB |
Output is correct |
44 |
Correct |
292 ms |
327508 KB |
Output is correct |
45 |
Correct |
211 ms |
312912 KB |
Output is correct |
46 |
Correct |
194 ms |
311416 KB |
Output is correct |
47 |
Correct |
255 ms |
324948 KB |
Output is correct |
48 |
Correct |
261 ms |
325972 KB |
Output is correct |
49 |
Correct |
133 ms |
296020 KB |
Output is correct |
50 |
Correct |
134 ms |
296020 KB |
Output is correct |
51 |
Correct |
139 ms |
295684 KB |
Output is correct |
52 |
Correct |
119 ms |
295504 KB |
Output is correct |
53 |
Correct |
136 ms |
295792 KB |
Output is correct |
54 |
Correct |
133 ms |
295764 KB |
Output is correct |
55 |
Correct |
134 ms |
296000 KB |
Output is correct |
56 |
Correct |
142 ms |
295764 KB |
Output is correct |
57 |
Correct |
132 ms |
295832 KB |
Output is correct |
58 |
Correct |
135 ms |
295508 KB |
Output is correct |
59 |
Correct |
134 ms |
295764 KB |
Output is correct |
60 |
Correct |
116 ms |
295752 KB |
Output is correct |
61 |
Correct |
604 ms |
391808 KB |
Output is correct |
62 |
Correct |
1257 ms |
502760 KB |
Output is correct |
63 |
Correct |
1239 ms |
503632 KB |
Output is correct |
64 |
Correct |
1238 ms |
503624 KB |
Output is correct |
65 |
Correct |
257 ms |
338000 KB |
Output is correct |
66 |
Correct |
453 ms |
377556 KB |
Output is correct |
67 |
Correct |
475 ms |
381264 KB |
Output is correct |
68 |
Correct |
104 ms |
295504 KB |
Output is correct |
69 |
Correct |
110 ms |
295524 KB |
Output is correct |
70 |
Correct |
112 ms |
295760 KB |
Output is correct |
71 |
Correct |
117 ms |
295508 KB |
Output is correct |
72 |
Correct |
124 ms |
295576 KB |
Output is correct |
73 |
Correct |
4712 ms |
565484 KB |
Output is correct |
74 |
Correct |
914 ms |
531996 KB |
Output is correct |
75 |
Correct |
1371 ms |
644504 KB |
Output is correct |
76 |
Correct |
1251 ms |
629552 KB |
Output is correct |
77 |
Correct |
1511 ms |
722216 KB |
Output is correct |
78 |
Correct |
1433 ms |
504216 KB |
Output is correct |
79 |
Correct |
1539 ms |
532720 KB |
Output is correct |
80 |
Correct |
2355 ms |
643416 KB |
Output is correct |
81 |
Correct |
1509 ms |
520596 KB |
Output is correct |
82 |
Correct |
2023 ms |
600228 KB |
Output is correct |
83 |
Correct |
2556 ms |
670348 KB |
Output is correct |
84 |
Correct |
1502 ms |
501924 KB |
Output is correct |
85 |
Correct |
2531 ms |
653324 KB |
Output is correct |
86 |
Correct |
2432 ms |
642628 KB |
Output is correct |
87 |
Correct |
867 ms |
559444 KB |
Output is correct |
88 |
Correct |
1374 ms |
721924 KB |
Output is correct |
89 |
Correct |
1405 ms |
722336 KB |
Output is correct |
90 |
Correct |
1409 ms |
722200 KB |
Output is correct |