# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
836440 |
2023-08-24T11:14:47 Z |
Antekb |
Rectangles (IOI19_rect) |
C++17 |
|
1848 ms |
89168 KB |
#include<bits/stdc++.h>
#include "rect.h"
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pii>;
using ll = long long;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
cerr<<h;
if(sizeof...(t))cerr<<", ";
debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
const int N=2505;
ll count_rectangles(std::vector<std::vector<int> > tab) {
int n=tab.size(), m=tab[0].size();
if(m<=2 || n<=2)return 0;
vector<vi> V2(m, {0});
for(int i=0; i<m; i++){
if(tab[1][i]>=tab[0][i]){
V2[i]={1};
}
else V2[i]={0, 1};
}
/*for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
//deb(i, j);
for(int k:par[i][j]){
//deb(k);
}
}
}*/
vector<pii> prv;
vi dp2;
ll ans=0;
vector<bitset<N> > suf(n);
for(int i=0; i<n; i++){
for(int j=i; j<n; j++)suf[i][j]=1;
}
for(int r=1; r<n-1; r++){
vector<bitset<N>> par(m);
for(int i=1; i<m-1; i++){
while(V2[i].size() && tab[r+1][i]>tab[V2[i].back()][i]){
if(V2[i].back()!=r)par[i][V2[i].back()]=1;
V2[i].pp();
}
if(V2[i].size() && V2[i].back()!=r)par[i][V2[i].back()]=1;
if(V2[i].size() && tab[V2[i].back()][i]==tab[r+1][i])V2[i].pp();
V2[i].pb(r+1);
}
vector<pii> akt;
vi dp;
vi V={m-1};
for(int j=m-2; j>=0; j--){
while(V.size() && tab[r][j]>tab[r][V.back()]){
if(V.back()!=j+1){
akt.eb(j, V.back());
}
V.pp();
}
if(V.size() && V.back()!=j+1){
akt.eb(j, V.back());
}
if(V.size() && tab[r][V.back()]==tab[r][j])V.pp();
V.pb(j);
}
dp.resize(akt.size(), 1);
int wsk=0;
for(int i=0; i<akt.size(); i++){
while(wsk<prv.size() && (akt[i].st<prv[wsk].st
|| (akt[i].st==prv[wsk].st && akt[i].nd>prv[wsk].nd)))wsk++;
if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk];
}
vi wsk2(m);
vector<int> S;
vector<bitset<N> > b(akt.size());
for(int i=0; i<akt.size(); i++){
//deb(r, i, akt[i].st, akt[i].nd, dp[i]);
b[i]=suf[0];
//for(int k=r-1; k>=r-dp[i]; k--)b[i][k]=1;
int pocz=akt[i].st+1;
while(S.size()){
int a=S.back();
if(akt[a].st>=akt[i].nd)break;
S.pp();
for(;pocz<=akt[a].st;pocz++){
b[i]&=par[pocz];
}
b[i]&=b[a];
pocz=akt[a].nd;
}
S.pb(i);
/*for(int j=0; j<i; j++){
if(akt[i].nd>=akt[j].nd){
assert(dp[i]<=dp[j]);
b[i]&=b[j];
}
}*/
for(;pocz<akt[i].nd;pocz++){
b[i]&=par[pocz];
}
ans+=(b[i]&suf[r-dp[i]]).count();
/*for(int k=r-1; k>=r-dp[i]; k--){
if(b[i][k]){
//deb(r, akt[i].st, akt[i].nd, k);
ans++;
}
}*/
}
prv=akt;
dp2=dp;
}
return ans;
}
Compilation message
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:83:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i=0; i<akt.size(); i++){
| ~^~~~~~~~~~~
rect.cpp:84:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | while(wsk<prv.size() && (akt[i].st<prv[wsk].st
| ~~~^~~~~~~~~~~
rect.cpp:86:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk];
| ~~~^~~~~~~~~~~
rect.cpp:91:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(int i=0; i<akt.size(); i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
3 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
10 ms |
980 KB |
Output is correct |
31 |
Correct |
10 ms |
980 KB |
Output is correct |
32 |
Correct |
10 ms |
980 KB |
Output is correct |
33 |
Correct |
6 ms |
724 KB |
Output is correct |
34 |
Correct |
11 ms |
892 KB |
Output is correct |
35 |
Correct |
11 ms |
852 KB |
Output is correct |
36 |
Correct |
11 ms |
852 KB |
Output is correct |
37 |
Correct |
11 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
10 ms |
980 KB |
Output is correct |
26 |
Correct |
10 ms |
980 KB |
Output is correct |
27 |
Correct |
10 ms |
980 KB |
Output is correct |
28 |
Correct |
6 ms |
724 KB |
Output is correct |
29 |
Correct |
11 ms |
892 KB |
Output is correct |
30 |
Correct |
11 ms |
852 KB |
Output is correct |
31 |
Correct |
11 ms |
852 KB |
Output is correct |
32 |
Correct |
11 ms |
852 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
74 ms |
6652 KB |
Output is correct |
39 |
Correct |
73 ms |
6668 KB |
Output is correct |
40 |
Correct |
76 ms |
6152 KB |
Output is correct |
41 |
Correct |
67 ms |
6144 KB |
Output is correct |
42 |
Correct |
119 ms |
7644 KB |
Output is correct |
43 |
Correct |
139 ms |
7680 KB |
Output is correct |
44 |
Correct |
131 ms |
7652 KB |
Output is correct |
45 |
Correct |
144 ms |
7388 KB |
Output is correct |
46 |
Correct |
57 ms |
4728 KB |
Output is correct |
47 |
Correct |
62 ms |
4780 KB |
Output is correct |
48 |
Correct |
131 ms |
5124 KB |
Output is correct |
49 |
Correct |
143 ms |
5116 KB |
Output is correct |
50 |
Correct |
70 ms |
2816 KB |
Output is correct |
51 |
Correct |
70 ms |
3048 KB |
Output is correct |
52 |
Correct |
134 ms |
5048 KB |
Output is correct |
53 |
Correct |
128 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2132 KB |
Output is correct |
2 |
Correct |
2 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
2132 KB |
Output is correct |
6 |
Correct |
3 ms |
2132 KB |
Output is correct |
7 |
Correct |
2 ms |
2132 KB |
Output is correct |
8 |
Correct |
2 ms |
2004 KB |
Output is correct |
9 |
Correct |
2 ms |
2004 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
265 ms |
24276 KB |
Output is correct |
8 |
Correct |
580 ms |
51236 KB |
Output is correct |
9 |
Correct |
578 ms |
51360 KB |
Output is correct |
10 |
Correct |
585 ms |
51320 KB |
Output is correct |
11 |
Correct |
70 ms |
25812 KB |
Output is correct |
12 |
Correct |
132 ms |
47956 KB |
Output is correct |
13 |
Correct |
146 ms |
51084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
10 ms |
980 KB |
Output is correct |
26 |
Correct |
10 ms |
980 KB |
Output is correct |
27 |
Correct |
10 ms |
980 KB |
Output is correct |
28 |
Correct |
6 ms |
724 KB |
Output is correct |
29 |
Correct |
11 ms |
892 KB |
Output is correct |
30 |
Correct |
11 ms |
852 KB |
Output is correct |
31 |
Correct |
11 ms |
852 KB |
Output is correct |
32 |
Correct |
11 ms |
852 KB |
Output is correct |
33 |
Correct |
74 ms |
6652 KB |
Output is correct |
34 |
Correct |
73 ms |
6668 KB |
Output is correct |
35 |
Correct |
76 ms |
6152 KB |
Output is correct |
36 |
Correct |
67 ms |
6144 KB |
Output is correct |
37 |
Correct |
119 ms |
7644 KB |
Output is correct |
38 |
Correct |
139 ms |
7680 KB |
Output is correct |
39 |
Correct |
131 ms |
7652 KB |
Output is correct |
40 |
Correct |
144 ms |
7388 KB |
Output is correct |
41 |
Correct |
57 ms |
4728 KB |
Output is correct |
42 |
Correct |
62 ms |
4780 KB |
Output is correct |
43 |
Correct |
131 ms |
5124 KB |
Output is correct |
44 |
Correct |
143 ms |
5116 KB |
Output is correct |
45 |
Correct |
70 ms |
2816 KB |
Output is correct |
46 |
Correct |
70 ms |
3048 KB |
Output is correct |
47 |
Correct |
134 ms |
5048 KB |
Output is correct |
48 |
Correct |
128 ms |
5120 KB |
Output is correct |
49 |
Correct |
2 ms |
2132 KB |
Output is correct |
50 |
Correct |
2 ms |
1748 KB |
Output is correct |
51 |
Correct |
1 ms |
1236 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
2 ms |
2132 KB |
Output is correct |
54 |
Correct |
3 ms |
2132 KB |
Output is correct |
55 |
Correct |
2 ms |
2132 KB |
Output is correct |
56 |
Correct |
2 ms |
2004 KB |
Output is correct |
57 |
Correct |
2 ms |
2004 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
265 ms |
24276 KB |
Output is correct |
62 |
Correct |
580 ms |
51236 KB |
Output is correct |
63 |
Correct |
578 ms |
51360 KB |
Output is correct |
64 |
Correct |
585 ms |
51320 KB |
Output is correct |
65 |
Correct |
70 ms |
25812 KB |
Output is correct |
66 |
Correct |
132 ms |
47956 KB |
Output is correct |
67 |
Correct |
146 ms |
51084 KB |
Output is correct |
68 |
Correct |
0 ms |
212 KB |
Output is correct |
69 |
Correct |
0 ms |
212 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
1004 ms |
70696 KB |
Output is correct |
74 |
Correct |
968 ms |
70856 KB |
Output is correct |
75 |
Correct |
1010 ms |
68796 KB |
Output is correct |
76 |
Correct |
1044 ms |
68824 KB |
Output is correct |
77 |
Correct |
1657 ms |
89120 KB |
Output is correct |
78 |
Correct |
1069 ms |
32780 KB |
Output is correct |
79 |
Correct |
1169 ms |
33664 KB |
Output is correct |
80 |
Correct |
1729 ms |
52808 KB |
Output is correct |
81 |
Correct |
1095 ms |
32944 KB |
Output is correct |
82 |
Correct |
1470 ms |
42488 KB |
Output is correct |
83 |
Correct |
1848 ms |
52828 KB |
Output is correct |
84 |
Correct |
1000 ms |
32996 KB |
Output is correct |
85 |
Correct |
1741 ms |
52808 KB |
Output is correct |
86 |
Correct |
1713 ms |
51560 KB |
Output is correct |
87 |
Correct |
979 ms |
54084 KB |
Output is correct |
88 |
Correct |
1640 ms |
89168 KB |
Output is correct |
89 |
Correct |
1643 ms |
89128 KB |
Output is correct |
90 |
Correct |
1634 ms |
89132 KB |
Output is correct |