# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1045874 |
2024-08-06T08:15:24 Z |
vjudge1 |
Rectangles (IOI19_rect) |
C++17 |
|
173 ms |
590588 KB |
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
set<int>pos[2501][2501],pos2[2501][2501];
set<int> operator & (const set<int>&a,const set<int>&b){
set<int>c;
if(a.size()<b.size()){
for(auto i:a)
if(b.count(i))
c.insert(i);
} else for(auto i:b)
if(a.count(i))
c.insert(i);
return c;
}
set<int>stb[2501][20];
int cnt(int l,int r){
int x=31-__builtin_clz(r-l+1);
return (stb[l][x]&stb[r-(1<<x)+1][x]).size();
}
long long count_rectangles(std::vector<std::vector<int> > a) {
int n=a.size(),m=a[0].size();
int ans=0;
for(int i=1;i<n-1;i++){
stack<int>stk;
stk.push(m-1);
for(int j=m-1;j--;){
while(stk.size()&&a[i][j]>a[i][stk.top()])
pos[i][j+1].insert(stk.top()-1),stk.pop();
if(stk.size()){
pos[i][j+1].insert(stk.top()-1);
if(a[i][stk.top()]==a[i][j])
stk.pop();
}
stk.push(j);
pos[i][j+1].erase(j);
}
}
for(int j=1;j<m-1;j++){
stack<int>stk;
stk.push(n-1);
for(int i=n-1;i--;){
while(stk.size()&&a[i][j]>a[stk.top()][j])
pos2[i+1][j].insert(stk.top()-1),stk.pop();
if(stk.size()){
pos2[i+1][j].insert(stk.top()-1);
if(a[stk.top()][j]==a[i][j])
stk.pop();
}
stk.push(i);
pos2[i+1][j].erase(i);
}
}
for(int col=1;col<m-1;col++){
for(int i=1;i<n-1;i++)
stb[i][0]=pos[i][col];
for(int j=1;j<20;j++)
for(int i=1;i+(1<<j)<n;i++)
stb[i][j]=stb[i][j-1]&stb[i+(1<<j-1)][j-1];
for(int row1=1;row1<n-1;row1++)
for(auto row2:pos2[row1][col])
ans+=cnt(row1,row2);
}
return ans;
}
Compilation message
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:59:50: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
59 | stb[i][j]=stb[i][j-1]&stb[i+(1<<j-1)][j-1];
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
590164 KB |
Output is correct |
2 |
Correct |
159 ms |
590160 KB |
Output is correct |
3 |
Correct |
168 ms |
590164 KB |
Output is correct |
4 |
Correct |
163 ms |
590416 KB |
Output is correct |
5 |
Correct |
159 ms |
590160 KB |
Output is correct |
6 |
Incorrect |
156 ms |
590312 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
590164 KB |
Output is correct |
2 |
Correct |
159 ms |
590160 KB |
Output is correct |
3 |
Correct |
168 ms |
590164 KB |
Output is correct |
4 |
Correct |
163 ms |
590416 KB |
Output is correct |
5 |
Correct |
159 ms |
590160 KB |
Output is correct |
6 |
Incorrect |
156 ms |
590312 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
590164 KB |
Output is correct |
2 |
Correct |
159 ms |
590160 KB |
Output is correct |
3 |
Correct |
168 ms |
590164 KB |
Output is correct |
4 |
Correct |
163 ms |
590416 KB |
Output is correct |
5 |
Correct |
159 ms |
590160 KB |
Output is correct |
6 |
Incorrect |
156 ms |
590312 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
590164 KB |
Output is correct |
2 |
Correct |
159 ms |
590160 KB |
Output is correct |
3 |
Correct |
168 ms |
590164 KB |
Output is correct |
4 |
Correct |
163 ms |
590416 KB |
Output is correct |
5 |
Correct |
159 ms |
590160 KB |
Output is correct |
6 |
Incorrect |
156 ms |
590312 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
590588 KB |
Output is correct |
2 |
Correct |
165 ms |
590420 KB |
Output is correct |
3 |
Correct |
155 ms |
590160 KB |
Output is correct |
4 |
Correct |
169 ms |
590132 KB |
Output is correct |
5 |
Incorrect |
173 ms |
590416 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
160 ms |
590308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
590164 KB |
Output is correct |
2 |
Correct |
159 ms |
590160 KB |
Output is correct |
3 |
Correct |
168 ms |
590164 KB |
Output is correct |
4 |
Correct |
163 ms |
590416 KB |
Output is correct |
5 |
Correct |
159 ms |
590160 KB |
Output is correct |
6 |
Incorrect |
156 ms |
590312 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |