# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1064928 |
2024-08-18T19:34:02 Z |
jerzyk |
Rectangles (IOI19_rect) |
C++17 |
|
1494 ms |
1048576 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 = 1<<12;
int drz[2 * N];
int tab[N][N];
vector<int> intr[N][N];
vector<pair<int, int>> que[N][N];
bool czy[N];
long long answer = 0;
void Add(int v, int x)
{
v += N;
while(v > 0)
{drz[v] += x; v /= 2;}
}
int Query(int a, int b)
{
a += N - 1; b += N + 1;
int ans = 0;
while(a / 2 != b / 2)
{
if(a % 2 == 0) ans += drz[a + 1];
if(b % 2 == 1) ans += drz[b - 1];
a /= 2; b /= 2;
}
return ans;
}
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();
k = -1;
//cout << "QUE: " << i << " " << j << "\n";
for(int l = 0; l < (int)que[i][j].size(); ++l)
{
while(k < lim - 1 && akt[k + 1].st <= que[i][j][l].st)
{
++k;
Add(i - akt[k].nd + 1, 1);
}
answer += (ll)Query(1, que[i][j][l].nd);
//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(k = k; k >= 0; --k)
Add(i - akt[k].nd + 1, -1);
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 |
279 ms |
788308 KB |
Output is correct |
2 |
Correct |
323 ms |
788492 KB |
Output is correct |
3 |
Correct |
287 ms |
788524 KB |
Output is correct |
4 |
Correct |
329 ms |
788560 KB |
Output is correct |
5 |
Correct |
275 ms |
788304 KB |
Output is correct |
6 |
Correct |
288 ms |
788560 KB |
Output is correct |
7 |
Correct |
291 ms |
788308 KB |
Output is correct |
8 |
Correct |
301 ms |
788432 KB |
Output is correct |
9 |
Correct |
297 ms |
788560 KB |
Output is correct |
10 |
Correct |
284 ms |
788388 KB |
Output is correct |
11 |
Correct |
463 ms |
788556 KB |
Output is correct |
12 |
Correct |
317 ms |
788412 KB |
Output is correct |
13 |
Correct |
413 ms |
788308 KB |
Output is correct |
14 |
Correct |
303 ms |
788308 KB |
Output is correct |
15 |
Correct |
286 ms |
788344 KB |
Output is correct |
16 |
Correct |
294 ms |
788196 KB |
Output is correct |
17 |
Correct |
277 ms |
788352 KB |
Output is correct |
18 |
Correct |
291 ms |
788304 KB |
Output is correct |
19 |
Correct |
287 ms |
788304 KB |
Output is correct |
20 |
Correct |
276 ms |
788308 KB |
Output is correct |
21 |
Correct |
272 ms |
788292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
788308 KB |
Output is correct |
2 |
Correct |
323 ms |
788492 KB |
Output is correct |
3 |
Correct |
287 ms |
788524 KB |
Output is correct |
4 |
Correct |
329 ms |
788560 KB |
Output is correct |
5 |
Correct |
275 ms |
788304 KB |
Output is correct |
6 |
Correct |
288 ms |
788560 KB |
Output is correct |
7 |
Correct |
291 ms |
788308 KB |
Output is correct |
8 |
Correct |
301 ms |
788432 KB |
Output is correct |
9 |
Correct |
297 ms |
788560 KB |
Output is correct |
10 |
Correct |
284 ms |
788388 KB |
Output is correct |
11 |
Correct |
463 ms |
788556 KB |
Output is correct |
12 |
Correct |
317 ms |
788412 KB |
Output is correct |
13 |
Correct |
413 ms |
788308 KB |
Output is correct |
14 |
Correct |
303 ms |
788308 KB |
Output is correct |
15 |
Correct |
286 ms |
788344 KB |
Output is correct |
16 |
Correct |
294 ms |
788196 KB |
Output is correct |
17 |
Correct |
277 ms |
788352 KB |
Output is correct |
18 |
Correct |
291 ms |
788304 KB |
Output is correct |
19 |
Correct |
287 ms |
788304 KB |
Output is correct |
20 |
Correct |
276 ms |
788308 KB |
Output is correct |
21 |
Correct |
272 ms |
788292 KB |
Output is correct |
22 |
Correct |
293 ms |
789072 KB |
Output is correct |
23 |
Correct |
282 ms |
788956 KB |
Output is correct |
24 |
Correct |
303 ms |
789072 KB |
Output is correct |
25 |
Correct |
286 ms |
788832 KB |
Output is correct |
26 |
Correct |
285 ms |
788816 KB |
Output is correct |
27 |
Correct |
282 ms |
788924 KB |
Output is correct |
28 |
Correct |
278 ms |
788988 KB |
Output is correct |
29 |
Correct |
293 ms |
788988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
788308 KB |
Output is correct |
2 |
Correct |
323 ms |
788492 KB |
Output is correct |
3 |
Correct |
287 ms |
788524 KB |
Output is correct |
4 |
Correct |
329 ms |
788560 KB |
Output is correct |
5 |
Correct |
275 ms |
788304 KB |
Output is correct |
6 |
Correct |
288 ms |
788560 KB |
Output is correct |
7 |
Correct |
291 ms |
788308 KB |
Output is correct |
8 |
Correct |
301 ms |
788432 KB |
Output is correct |
9 |
Correct |
297 ms |
788560 KB |
Output is correct |
10 |
Correct |
284 ms |
788388 KB |
Output is correct |
11 |
Correct |
463 ms |
788556 KB |
Output is correct |
12 |
Correct |
317 ms |
788412 KB |
Output is correct |
13 |
Correct |
413 ms |
788308 KB |
Output is correct |
14 |
Correct |
303 ms |
788308 KB |
Output is correct |
15 |
Correct |
286 ms |
788344 KB |
Output is correct |
16 |
Correct |
294 ms |
788196 KB |
Output is correct |
17 |
Correct |
293 ms |
789072 KB |
Output is correct |
18 |
Correct |
282 ms |
788956 KB |
Output is correct |
19 |
Correct |
303 ms |
789072 KB |
Output is correct |
20 |
Correct |
286 ms |
788832 KB |
Output is correct |
21 |
Correct |
285 ms |
788816 KB |
Output is correct |
22 |
Correct |
282 ms |
788924 KB |
Output is correct |
23 |
Correct |
278 ms |
788988 KB |
Output is correct |
24 |
Correct |
293 ms |
788988 KB |
Output is correct |
25 |
Correct |
277 ms |
788352 KB |
Output is correct |
26 |
Correct |
291 ms |
788304 KB |
Output is correct |
27 |
Correct |
287 ms |
788304 KB |
Output is correct |
28 |
Correct |
276 ms |
788308 KB |
Output is correct |
29 |
Correct |
272 ms |
788292 KB |
Output is correct |
30 |
Correct |
293 ms |
791376 KB |
Output is correct |
31 |
Correct |
305 ms |
791556 KB |
Output is correct |
32 |
Correct |
299 ms |
791332 KB |
Output is correct |
33 |
Correct |
278 ms |
790476 KB |
Output is correct |
34 |
Correct |
299 ms |
791120 KB |
Output is correct |
35 |
Correct |
295 ms |
791088 KB |
Output is correct |
36 |
Correct |
320 ms |
790952 KB |
Output is correct |
37 |
Correct |
307 ms |
790980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
788308 KB |
Output is correct |
2 |
Correct |
323 ms |
788492 KB |
Output is correct |
3 |
Correct |
287 ms |
788524 KB |
Output is correct |
4 |
Correct |
329 ms |
788560 KB |
Output is correct |
5 |
Correct |
275 ms |
788304 KB |
Output is correct |
6 |
Correct |
288 ms |
788560 KB |
Output is correct |
7 |
Correct |
291 ms |
788308 KB |
Output is correct |
8 |
Correct |
301 ms |
788432 KB |
Output is correct |
9 |
Correct |
297 ms |
788560 KB |
Output is correct |
10 |
Correct |
284 ms |
788388 KB |
Output is correct |
11 |
Correct |
463 ms |
788556 KB |
Output is correct |
12 |
Correct |
317 ms |
788412 KB |
Output is correct |
13 |
Correct |
413 ms |
788308 KB |
Output is correct |
14 |
Correct |
303 ms |
788308 KB |
Output is correct |
15 |
Correct |
286 ms |
788344 KB |
Output is correct |
16 |
Correct |
294 ms |
788196 KB |
Output is correct |
17 |
Correct |
293 ms |
789072 KB |
Output is correct |
18 |
Correct |
282 ms |
788956 KB |
Output is correct |
19 |
Correct |
303 ms |
789072 KB |
Output is correct |
20 |
Correct |
286 ms |
788832 KB |
Output is correct |
21 |
Correct |
285 ms |
788816 KB |
Output is correct |
22 |
Correct |
282 ms |
788924 KB |
Output is correct |
23 |
Correct |
278 ms |
788988 KB |
Output is correct |
24 |
Correct |
293 ms |
788988 KB |
Output is correct |
25 |
Correct |
293 ms |
791376 KB |
Output is correct |
26 |
Correct |
305 ms |
791556 KB |
Output is correct |
27 |
Correct |
299 ms |
791332 KB |
Output is correct |
28 |
Correct |
278 ms |
790476 KB |
Output is correct |
29 |
Correct |
299 ms |
791120 KB |
Output is correct |
30 |
Correct |
295 ms |
791088 KB |
Output is correct |
31 |
Correct |
320 ms |
790952 KB |
Output is correct |
32 |
Correct |
307 ms |
790980 KB |
Output is correct |
33 |
Correct |
277 ms |
788352 KB |
Output is correct |
34 |
Correct |
291 ms |
788304 KB |
Output is correct |
35 |
Correct |
287 ms |
788304 KB |
Output is correct |
36 |
Correct |
276 ms |
788308 KB |
Output is correct |
37 |
Correct |
272 ms |
788292 KB |
Output is correct |
38 |
Correct |
367 ms |
809760 KB |
Output is correct |
39 |
Correct |
349 ms |
806812 KB |
Output is correct |
40 |
Correct |
353 ms |
815956 KB |
Output is correct |
41 |
Correct |
371 ms |
814420 KB |
Output is correct |
42 |
Correct |
391 ms |
821588 KB |
Output is correct |
43 |
Correct |
380 ms |
821496 KB |
Output is correct |
44 |
Correct |
389 ms |
821588 KB |
Output is correct |
45 |
Correct |
367 ms |
819620 KB |
Output is correct |
46 |
Correct |
360 ms |
807252 KB |
Output is correct |
47 |
Correct |
381 ms |
810236 KB |
Output is correct |
48 |
Correct |
452 ms |
817456 KB |
Output is correct |
49 |
Correct |
450 ms |
817476 KB |
Output is correct |
50 |
Correct |
361 ms |
802900 KB |
Output is correct |
51 |
Correct |
357 ms |
802896 KB |
Output is correct |
52 |
Correct |
438 ms |
816072 KB |
Output is correct |
53 |
Correct |
457 ms |
816024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
788632 KB |
Output is correct |
2 |
Correct |
296 ms |
788656 KB |
Output is correct |
3 |
Correct |
297 ms |
788304 KB |
Output is correct |
4 |
Correct |
290 ms |
788308 KB |
Output is correct |
5 |
Correct |
308 ms |
788736 KB |
Output is correct |
6 |
Correct |
293 ms |
788564 KB |
Output is correct |
7 |
Correct |
299 ms |
788560 KB |
Output is correct |
8 |
Correct |
305 ms |
788600 KB |
Output is correct |
9 |
Correct |
302 ms |
788564 KB |
Output is correct |
10 |
Correct |
329 ms |
788340 KB |
Output is correct |
11 |
Correct |
313 ms |
788572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
277 ms |
788352 KB |
Output is correct |
2 |
Correct |
291 ms |
788304 KB |
Output is correct |
3 |
Correct |
287 ms |
788304 KB |
Output is correct |
4 |
Correct |
276 ms |
788308 KB |
Output is correct |
5 |
Correct |
272 ms |
788292 KB |
Output is correct |
6 |
Correct |
276 ms |
788560 KB |
Output is correct |
7 |
Correct |
754 ms |
881748 KB |
Output is correct |
8 |
Correct |
1370 ms |
988756 KB |
Output is correct |
9 |
Correct |
1399 ms |
989688 KB |
Output is correct |
10 |
Correct |
1407 ms |
989776 KB |
Output is correct |
11 |
Correct |
464 ms |
827476 KB |
Output is correct |
12 |
Correct |
632 ms |
864340 KB |
Output is correct |
13 |
Correct |
627 ms |
867412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
788308 KB |
Output is correct |
2 |
Correct |
323 ms |
788492 KB |
Output is correct |
3 |
Correct |
287 ms |
788524 KB |
Output is correct |
4 |
Correct |
329 ms |
788560 KB |
Output is correct |
5 |
Correct |
275 ms |
788304 KB |
Output is correct |
6 |
Correct |
288 ms |
788560 KB |
Output is correct |
7 |
Correct |
291 ms |
788308 KB |
Output is correct |
8 |
Correct |
301 ms |
788432 KB |
Output is correct |
9 |
Correct |
297 ms |
788560 KB |
Output is correct |
10 |
Correct |
284 ms |
788388 KB |
Output is correct |
11 |
Correct |
463 ms |
788556 KB |
Output is correct |
12 |
Correct |
317 ms |
788412 KB |
Output is correct |
13 |
Correct |
413 ms |
788308 KB |
Output is correct |
14 |
Correct |
303 ms |
788308 KB |
Output is correct |
15 |
Correct |
286 ms |
788344 KB |
Output is correct |
16 |
Correct |
294 ms |
788196 KB |
Output is correct |
17 |
Correct |
293 ms |
789072 KB |
Output is correct |
18 |
Correct |
282 ms |
788956 KB |
Output is correct |
19 |
Correct |
303 ms |
789072 KB |
Output is correct |
20 |
Correct |
286 ms |
788832 KB |
Output is correct |
21 |
Correct |
285 ms |
788816 KB |
Output is correct |
22 |
Correct |
282 ms |
788924 KB |
Output is correct |
23 |
Correct |
278 ms |
788988 KB |
Output is correct |
24 |
Correct |
293 ms |
788988 KB |
Output is correct |
25 |
Correct |
293 ms |
791376 KB |
Output is correct |
26 |
Correct |
305 ms |
791556 KB |
Output is correct |
27 |
Correct |
299 ms |
791332 KB |
Output is correct |
28 |
Correct |
278 ms |
790476 KB |
Output is correct |
29 |
Correct |
299 ms |
791120 KB |
Output is correct |
30 |
Correct |
295 ms |
791088 KB |
Output is correct |
31 |
Correct |
320 ms |
790952 KB |
Output is correct |
32 |
Correct |
307 ms |
790980 KB |
Output is correct |
33 |
Correct |
367 ms |
809760 KB |
Output is correct |
34 |
Correct |
349 ms |
806812 KB |
Output is correct |
35 |
Correct |
353 ms |
815956 KB |
Output is correct |
36 |
Correct |
371 ms |
814420 KB |
Output is correct |
37 |
Correct |
391 ms |
821588 KB |
Output is correct |
38 |
Correct |
380 ms |
821496 KB |
Output is correct |
39 |
Correct |
389 ms |
821588 KB |
Output is correct |
40 |
Correct |
367 ms |
819620 KB |
Output is correct |
41 |
Correct |
360 ms |
807252 KB |
Output is correct |
42 |
Correct |
381 ms |
810236 KB |
Output is correct |
43 |
Correct |
452 ms |
817456 KB |
Output is correct |
44 |
Correct |
450 ms |
817476 KB |
Output is correct |
45 |
Correct |
361 ms |
802900 KB |
Output is correct |
46 |
Correct |
357 ms |
802896 KB |
Output is correct |
47 |
Correct |
438 ms |
816072 KB |
Output is correct |
48 |
Correct |
457 ms |
816024 KB |
Output is correct |
49 |
Correct |
301 ms |
788632 KB |
Output is correct |
50 |
Correct |
296 ms |
788656 KB |
Output is correct |
51 |
Correct |
297 ms |
788304 KB |
Output is correct |
52 |
Correct |
290 ms |
788308 KB |
Output is correct |
53 |
Correct |
308 ms |
788736 KB |
Output is correct |
54 |
Correct |
293 ms |
788564 KB |
Output is correct |
55 |
Correct |
299 ms |
788560 KB |
Output is correct |
56 |
Correct |
305 ms |
788600 KB |
Output is correct |
57 |
Correct |
302 ms |
788564 KB |
Output is correct |
58 |
Correct |
329 ms |
788340 KB |
Output is correct |
59 |
Correct |
313 ms |
788572 KB |
Output is correct |
60 |
Correct |
276 ms |
788560 KB |
Output is correct |
61 |
Correct |
754 ms |
881748 KB |
Output is correct |
62 |
Correct |
1370 ms |
988756 KB |
Output is correct |
63 |
Correct |
1399 ms |
989688 KB |
Output is correct |
64 |
Correct |
1407 ms |
989776 KB |
Output is correct |
65 |
Correct |
464 ms |
827476 KB |
Output is correct |
66 |
Correct |
632 ms |
864340 KB |
Output is correct |
67 |
Correct |
627 ms |
867412 KB |
Output is correct |
68 |
Correct |
277 ms |
788352 KB |
Output is correct |
69 |
Correct |
291 ms |
788304 KB |
Output is correct |
70 |
Correct |
287 ms |
788304 KB |
Output is correct |
71 |
Correct |
276 ms |
788308 KB |
Output is correct |
72 |
Correct |
272 ms |
788292 KB |
Output is correct |
73 |
Correct |
1494 ms |
1017168 KB |
Output is correct |
74 |
Correct |
1079 ms |
983512 KB |
Output is correct |
75 |
Runtime error |
1028 ms |
1048576 KB |
Execution killed with signal 9 |
76 |
Halted |
0 ms |
0 KB |
- |