# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
836488 |
2023-08-24T11:48:04 Z |
Rafi22 |
Rectangles (IOI19_rect) |
C++14 |
|
5000 ms |
868456 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define st first
#define nd second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
int inf=1000000007;
ll infl=1000000000000000007;
const int N=2507,pot=1<<12;
set<int>V[N][N];
int U[N][2*pot+7];
int D[N][2*pot+7];
int n,m;
int queU(int v,int a,int b,int l,int r,int i)
{
if(a<=l&&b>=r) return U[i][v];
if(r<a||l>b) return -1;
return max(queU(2*v,a,b,l,(l+r)/2,i),queU(2*v+1,a,b,(l+r)/2+1,r,i));
}
int queD(int v,int a,int b,int l,int r,int i)
{
if(a<=l&&b>=r) return D[i][v];
if(r<a||l>b) return n;
return min(queD(2*v,a,b,l,(l+r)/2,i),queD(2*v+1,a,b,(l+r)/2+1,r,i));
}
int BIT[N];
int que(int x)
{
int s=0;
for (;x;x-=x&-x) s+=BIT[x];
return s;
}
void ins(int x,int s) {
for (;x<N;x+=x&-x) BIT[x]+=s;
}
ll count_rectangles(vector<vector<int>>a)
{
ll ans=0;
n=sz(a),m=sz(a[0]);
for(int i=1;i<n-1;i++)
{
deque<pair<int,int>>Q;
Q.pb({a[i][0],0});
for(int j=1;j<m;j++)
{
while(sz(Q)>0&&Q.back().st<a[i][j]) Q.pop_back();
if(sz(Q)>0) V[Q.back().nd+1][j-1].insert(i);
Q.pb({a[i][j],j});
}
Q.clear();
Q.pb({a[i][m-1],m-1});
for(int j=m-2;j>=0;j--)
{
while(sz(Q)>0&&Q.back().st<a[i][j]) Q.pop_back();
if(sz(Q)>0) V[j+1][Q.back().nd-1].insert(i);
Q.pb({a[i][j],j});
}
}
for(int i=0;i<n;i++)
{
for(int j=1;j<2*pot;j++)
{
U[i][j]=-1;
D[i][j]=n;
}
}
for(int j=0;j<m;j++)
{
deque<pair<int,int>>Q;
Q.pb({a[0][j],0});
for(int i=1;i<n;i++)
{
while(sz(Q)>0&&Q.back().st<a[i][j]) Q.pop_back();
if(sz(Q)>0) U[i][j+pot]=Q.back().nd;
Q.pb({a[i][j],i});
}
Q.clear();
Q.pb({a[n-1][j],n-1});
for(int i=n-2;i>=0;i--)
{
while(sz(Q)>0&&Q.back().st<a[i][j]) Q.pop_back();
if(sz(Q)>0) D[i][j+pot]=Q.back().nd;;
Q.pb({a[i][j],i});
}
}
for(int i=0;i<n;i++)
{
for(int j=pot-1;j>0;j--)
{
U[i][j]=max(U[i][2*j],U[i][2*j+1]);
D[i][j]=min(D[i][2*j],D[i][2*j+1]);
}
}
for(int i=0;i<m;i++)
{
for(int j=i;j<m;j++)
{
if(sz(V[i][j])==0) continue;
//cout<<i<<" "<<j<<endl;
vector<pair<int,int>>E;
int l=-1;
for(auto x:V[i][j])
{
int k=queD(1,i+1,j+1,1,pot,x-1);
if(k==x)
{
E.pb({x,inf-1});
}
else
{
E.pb({x,inf});
E.pb({k,x});
}
if(x!=l+1) E.pb({x,-inf});
l=x;
}
sort(all(E));
set<int>alive;
for(auto [x,c]:E)
{
//cout<<x<<" "<<c<<endl;
if(c==-inf)
{
for(auto y:alive) ins(y+1,-1);
alive.clear();
}
else if(c==inf)
{
ins(x+1,1);
ans+=(ll)que(x+1)-que(queU(1,i+1,j+1,1,pot,x+1)+1);
alive.insert(x);
}
else if(c==inf-1) ans+=(ll)que(x+1)-que(queU(1,i+1,j+1,1,pot,x+1)+1);
else
{
if(alive.count(c))
{
alive.erase(c);
ins(c+1,-1);
}
}
}
for(auto x:alive) ins(x+1,-1);
// cout<<ans<<endl;
}
}
return ans;
}
/*
int main()
{
cout<<count_rectangles({
{4, 8, 7, 5, 6},
{7, 4, 10, 3, 5},
{9, 7, 20, 14, 2},
{9, 14, 7, 3, 6},
{5, 7, 5, 2, 7},
{4, 5, 13, 5, 6}})<<endl;
return 0;
}*/
Compilation message
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:132:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
132 | for(auto [x,c]:E)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
295764 KB |
Output is correct |
2 |
Correct |
126 ms |
297448 KB |
Output is correct |
3 |
Correct |
121 ms |
297488 KB |
Output is correct |
4 |
Correct |
118 ms |
297448 KB |
Output is correct |
5 |
Correct |
137 ms |
297420 KB |
Output is correct |
6 |
Correct |
122 ms |
297416 KB |
Output is correct |
7 |
Correct |
118 ms |
297396 KB |
Output is correct |
8 |
Correct |
117 ms |
296200 KB |
Output is correct |
9 |
Correct |
125 ms |
297584 KB |
Output is correct |
10 |
Correct |
131 ms |
297432 KB |
Output is correct |
11 |
Correct |
117 ms |
297496 KB |
Output is correct |
12 |
Correct |
120 ms |
297452 KB |
Output is correct |
13 |
Correct |
117 ms |
295548 KB |
Output is correct |
14 |
Correct |
121 ms |
296128 KB |
Output is correct |
15 |
Correct |
127 ms |
296068 KB |
Output is correct |
16 |
Correct |
121 ms |
295668 KB |
Output is correct |
17 |
Correct |
119 ms |
295544 KB |
Output is correct |
18 |
Correct |
120 ms |
295428 KB |
Output is correct |
19 |
Correct |
119 ms |
297444 KB |
Output is correct |
20 |
Correct |
124 ms |
297408 KB |
Output is correct |
21 |
Correct |
117 ms |
296028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
295764 KB |
Output is correct |
2 |
Correct |
126 ms |
297448 KB |
Output is correct |
3 |
Correct |
121 ms |
297488 KB |
Output is correct |
4 |
Correct |
118 ms |
297448 KB |
Output is correct |
5 |
Correct |
137 ms |
297420 KB |
Output is correct |
6 |
Correct |
122 ms |
297416 KB |
Output is correct |
7 |
Correct |
118 ms |
297396 KB |
Output is correct |
8 |
Correct |
117 ms |
296200 KB |
Output is correct |
9 |
Correct |
125 ms |
297584 KB |
Output is correct |
10 |
Correct |
131 ms |
297432 KB |
Output is correct |
11 |
Correct |
117 ms |
297496 KB |
Output is correct |
12 |
Correct |
120 ms |
297452 KB |
Output is correct |
13 |
Correct |
117 ms |
295548 KB |
Output is correct |
14 |
Correct |
121 ms |
296128 KB |
Output is correct |
15 |
Correct |
127 ms |
296068 KB |
Output is correct |
16 |
Correct |
121 ms |
295668 KB |
Output is correct |
17 |
Correct |
119 ms |
295544 KB |
Output is correct |
18 |
Correct |
120 ms |
295428 KB |
Output is correct |
19 |
Correct |
119 ms |
297444 KB |
Output is correct |
20 |
Correct |
124 ms |
297408 KB |
Output is correct |
21 |
Correct |
117 ms |
296028 KB |
Output is correct |
22 |
Correct |
124 ms |
301268 KB |
Output is correct |
23 |
Correct |
125 ms |
301236 KB |
Output is correct |
24 |
Correct |
122 ms |
301260 KB |
Output is correct |
25 |
Correct |
124 ms |
301056 KB |
Output is correct |
26 |
Correct |
123 ms |
301048 KB |
Output is correct |
27 |
Correct |
125 ms |
301120 KB |
Output is correct |
28 |
Correct |
123 ms |
301128 KB |
Output is correct |
29 |
Correct |
120 ms |
300856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
295764 KB |
Output is correct |
2 |
Correct |
126 ms |
297448 KB |
Output is correct |
3 |
Correct |
121 ms |
297488 KB |
Output is correct |
4 |
Correct |
118 ms |
297448 KB |
Output is correct |
5 |
Correct |
137 ms |
297420 KB |
Output is correct |
6 |
Correct |
122 ms |
297416 KB |
Output is correct |
7 |
Correct |
118 ms |
297396 KB |
Output is correct |
8 |
Correct |
117 ms |
296200 KB |
Output is correct |
9 |
Correct |
125 ms |
297584 KB |
Output is correct |
10 |
Correct |
131 ms |
297432 KB |
Output is correct |
11 |
Correct |
117 ms |
297496 KB |
Output is correct |
12 |
Correct |
120 ms |
297452 KB |
Output is correct |
13 |
Correct |
117 ms |
295548 KB |
Output is correct |
14 |
Correct |
121 ms |
296128 KB |
Output is correct |
15 |
Correct |
127 ms |
296068 KB |
Output is correct |
16 |
Correct |
121 ms |
295668 KB |
Output is correct |
17 |
Correct |
124 ms |
301268 KB |
Output is correct |
18 |
Correct |
125 ms |
301236 KB |
Output is correct |
19 |
Correct |
122 ms |
301260 KB |
Output is correct |
20 |
Correct |
124 ms |
301056 KB |
Output is correct |
21 |
Correct |
123 ms |
301048 KB |
Output is correct |
22 |
Correct |
125 ms |
301120 KB |
Output is correct |
23 |
Correct |
123 ms |
301128 KB |
Output is correct |
24 |
Correct |
120 ms |
300856 KB |
Output is correct |
25 |
Correct |
119 ms |
295544 KB |
Output is correct |
26 |
Correct |
120 ms |
295428 KB |
Output is correct |
27 |
Correct |
119 ms |
297444 KB |
Output is correct |
28 |
Correct |
124 ms |
297408 KB |
Output is correct |
29 |
Correct |
117 ms |
296028 KB |
Output is correct |
30 |
Correct |
151 ms |
312304 KB |
Output is correct |
31 |
Correct |
150 ms |
312360 KB |
Output is correct |
32 |
Correct |
154 ms |
312336 KB |
Output is correct |
33 |
Correct |
150 ms |
311204 KB |
Output is correct |
34 |
Correct |
151 ms |
312240 KB |
Output is correct |
35 |
Correct |
148 ms |
312204 KB |
Output is correct |
36 |
Correct |
150 ms |
312144 KB |
Output is correct |
37 |
Correct |
150 ms |
312012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
295764 KB |
Output is correct |
2 |
Correct |
126 ms |
297448 KB |
Output is correct |
3 |
Correct |
121 ms |
297488 KB |
Output is correct |
4 |
Correct |
118 ms |
297448 KB |
Output is correct |
5 |
Correct |
137 ms |
297420 KB |
Output is correct |
6 |
Correct |
122 ms |
297416 KB |
Output is correct |
7 |
Correct |
118 ms |
297396 KB |
Output is correct |
8 |
Correct |
117 ms |
296200 KB |
Output is correct |
9 |
Correct |
125 ms |
297584 KB |
Output is correct |
10 |
Correct |
131 ms |
297432 KB |
Output is correct |
11 |
Correct |
117 ms |
297496 KB |
Output is correct |
12 |
Correct |
120 ms |
297452 KB |
Output is correct |
13 |
Correct |
117 ms |
295548 KB |
Output is correct |
14 |
Correct |
121 ms |
296128 KB |
Output is correct |
15 |
Correct |
127 ms |
296068 KB |
Output is correct |
16 |
Correct |
121 ms |
295668 KB |
Output is correct |
17 |
Correct |
124 ms |
301268 KB |
Output is correct |
18 |
Correct |
125 ms |
301236 KB |
Output is correct |
19 |
Correct |
122 ms |
301260 KB |
Output is correct |
20 |
Correct |
124 ms |
301056 KB |
Output is correct |
21 |
Correct |
123 ms |
301048 KB |
Output is correct |
22 |
Correct |
125 ms |
301120 KB |
Output is correct |
23 |
Correct |
123 ms |
301128 KB |
Output is correct |
24 |
Correct |
120 ms |
300856 KB |
Output is correct |
25 |
Correct |
151 ms |
312304 KB |
Output is correct |
26 |
Correct |
150 ms |
312360 KB |
Output is correct |
27 |
Correct |
154 ms |
312336 KB |
Output is correct |
28 |
Correct |
150 ms |
311204 KB |
Output is correct |
29 |
Correct |
151 ms |
312240 KB |
Output is correct |
30 |
Correct |
148 ms |
312204 KB |
Output is correct |
31 |
Correct |
150 ms |
312144 KB |
Output is correct |
32 |
Correct |
150 ms |
312012 KB |
Output is correct |
33 |
Correct |
119 ms |
295544 KB |
Output is correct |
34 |
Correct |
120 ms |
295428 KB |
Output is correct |
35 |
Correct |
119 ms |
297444 KB |
Output is correct |
36 |
Correct |
124 ms |
297408 KB |
Output is correct |
37 |
Correct |
117 ms |
296028 KB |
Output is correct |
38 |
Correct |
380 ms |
378676 KB |
Output is correct |
39 |
Correct |
331 ms |
378612 KB |
Output is correct |
40 |
Correct |
414 ms |
378692 KB |
Output is correct |
41 |
Correct |
349 ms |
378684 KB |
Output is correct |
42 |
Correct |
642 ms |
390056 KB |
Output is correct |
43 |
Correct |
620 ms |
390144 KB |
Output is correct |
44 |
Correct |
620 ms |
390152 KB |
Output is correct |
45 |
Correct |
590 ms |
383932 KB |
Output is correct |
46 |
Correct |
417 ms |
372916 KB |
Output is correct |
47 |
Correct |
483 ms |
376084 KB |
Output is correct |
48 |
Correct |
747 ms |
389472 KB |
Output is correct |
49 |
Correct |
866 ms |
389744 KB |
Output is correct |
50 |
Correct |
386 ms |
364920 KB |
Output is correct |
51 |
Correct |
366 ms |
342476 KB |
Output is correct |
52 |
Correct |
682 ms |
387856 KB |
Output is correct |
53 |
Correct |
727 ms |
387904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
295892 KB |
Output is correct |
2 |
Correct |
128 ms |
295920 KB |
Output is correct |
3 |
Correct |
136 ms |
295860 KB |
Output is correct |
4 |
Correct |
123 ms |
295620 KB |
Output is correct |
5 |
Correct |
132 ms |
295924 KB |
Output is correct |
6 |
Correct |
135 ms |
295968 KB |
Output is correct |
7 |
Correct |
134 ms |
295968 KB |
Output is correct |
8 |
Correct |
133 ms |
295964 KB |
Output is correct |
9 |
Correct |
151 ms |
296056 KB |
Output is correct |
10 |
Correct |
145 ms |
295496 KB |
Output is correct |
11 |
Correct |
128 ms |
295536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
295544 KB |
Output is correct |
2 |
Correct |
120 ms |
295428 KB |
Output is correct |
3 |
Correct |
119 ms |
297444 KB |
Output is correct |
4 |
Correct |
124 ms |
297408 KB |
Output is correct |
5 |
Correct |
117 ms |
296028 KB |
Output is correct |
6 |
Correct |
118 ms |
296140 KB |
Output is correct |
7 |
Correct |
2478 ms |
564976 KB |
Output is correct |
8 |
Execution timed out |
5112 ms |
868456 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
295764 KB |
Output is correct |
2 |
Correct |
126 ms |
297448 KB |
Output is correct |
3 |
Correct |
121 ms |
297488 KB |
Output is correct |
4 |
Correct |
118 ms |
297448 KB |
Output is correct |
5 |
Correct |
137 ms |
297420 KB |
Output is correct |
6 |
Correct |
122 ms |
297416 KB |
Output is correct |
7 |
Correct |
118 ms |
297396 KB |
Output is correct |
8 |
Correct |
117 ms |
296200 KB |
Output is correct |
9 |
Correct |
125 ms |
297584 KB |
Output is correct |
10 |
Correct |
131 ms |
297432 KB |
Output is correct |
11 |
Correct |
117 ms |
297496 KB |
Output is correct |
12 |
Correct |
120 ms |
297452 KB |
Output is correct |
13 |
Correct |
117 ms |
295548 KB |
Output is correct |
14 |
Correct |
121 ms |
296128 KB |
Output is correct |
15 |
Correct |
127 ms |
296068 KB |
Output is correct |
16 |
Correct |
121 ms |
295668 KB |
Output is correct |
17 |
Correct |
124 ms |
301268 KB |
Output is correct |
18 |
Correct |
125 ms |
301236 KB |
Output is correct |
19 |
Correct |
122 ms |
301260 KB |
Output is correct |
20 |
Correct |
124 ms |
301056 KB |
Output is correct |
21 |
Correct |
123 ms |
301048 KB |
Output is correct |
22 |
Correct |
125 ms |
301120 KB |
Output is correct |
23 |
Correct |
123 ms |
301128 KB |
Output is correct |
24 |
Correct |
120 ms |
300856 KB |
Output is correct |
25 |
Correct |
151 ms |
312304 KB |
Output is correct |
26 |
Correct |
150 ms |
312360 KB |
Output is correct |
27 |
Correct |
154 ms |
312336 KB |
Output is correct |
28 |
Correct |
150 ms |
311204 KB |
Output is correct |
29 |
Correct |
151 ms |
312240 KB |
Output is correct |
30 |
Correct |
148 ms |
312204 KB |
Output is correct |
31 |
Correct |
150 ms |
312144 KB |
Output is correct |
32 |
Correct |
150 ms |
312012 KB |
Output is correct |
33 |
Correct |
380 ms |
378676 KB |
Output is correct |
34 |
Correct |
331 ms |
378612 KB |
Output is correct |
35 |
Correct |
414 ms |
378692 KB |
Output is correct |
36 |
Correct |
349 ms |
378684 KB |
Output is correct |
37 |
Correct |
642 ms |
390056 KB |
Output is correct |
38 |
Correct |
620 ms |
390144 KB |
Output is correct |
39 |
Correct |
620 ms |
390152 KB |
Output is correct |
40 |
Correct |
590 ms |
383932 KB |
Output is correct |
41 |
Correct |
417 ms |
372916 KB |
Output is correct |
42 |
Correct |
483 ms |
376084 KB |
Output is correct |
43 |
Correct |
747 ms |
389472 KB |
Output is correct |
44 |
Correct |
866 ms |
389744 KB |
Output is correct |
45 |
Correct |
386 ms |
364920 KB |
Output is correct |
46 |
Correct |
366 ms |
342476 KB |
Output is correct |
47 |
Correct |
682 ms |
387856 KB |
Output is correct |
48 |
Correct |
727 ms |
387904 KB |
Output is correct |
49 |
Correct |
144 ms |
295892 KB |
Output is correct |
50 |
Correct |
128 ms |
295920 KB |
Output is correct |
51 |
Correct |
136 ms |
295860 KB |
Output is correct |
52 |
Correct |
123 ms |
295620 KB |
Output is correct |
53 |
Correct |
132 ms |
295924 KB |
Output is correct |
54 |
Correct |
135 ms |
295968 KB |
Output is correct |
55 |
Correct |
134 ms |
295968 KB |
Output is correct |
56 |
Correct |
133 ms |
295964 KB |
Output is correct |
57 |
Correct |
151 ms |
296056 KB |
Output is correct |
58 |
Correct |
145 ms |
295496 KB |
Output is correct |
59 |
Correct |
128 ms |
295536 KB |
Output is correct |
60 |
Correct |
118 ms |
296140 KB |
Output is correct |
61 |
Correct |
2478 ms |
564976 KB |
Output is correct |
62 |
Execution timed out |
5112 ms |
868456 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |