#include<bits/stdc++.h>
#include <cstdio>
#include <unistd.h>
#include <cassert>
#include <string>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
const int nax=2505;
int segtree[nax*4];
int tab[nax];
vector<vector<int>> grid;
void build(int pos,int l,int r){
if(l==r){
segtree[pos]=grid[1][l];
return;
}
int mid=(r+l)/2;
build(pos*2+1,l,mid);
build(pos*2+2,mid+1,r);
segtree[pos]=max(segtree[pos*2+1],segtree[pos*2+2]);
}
int query(int pos,int l,int r,int left,int right){
if(l>r||l>right||r<left) return -1e9;
if(l>=left&&r<=right) return segtree[pos];
int mid=(r+l)/2;
return max(query(pos*2+1,l,mid,left,right),query(pos*2+2,mid+1,r,left,right));
}
int seg[nax*4];
void build1(int pos,int l,int r){
if(l==r){
seg[pos]=tab[l];
return;
}
int mid=(r+l)/2;
build(pos*2+1,l,mid);
build(pos*2+2,mid+1,r);
seg[pos]=seg[pos*2+1]|seg[pos*2+2];
}
int query1(int pos,int l,int r,int left,int right){
if(l>r||l>right||r<left) return 0;
if(l>=left&&r<=right) return seg[pos];
int mid=(r+l)/2;
return query1(pos*2+1,l,mid,left,right)|query1(pos*2+2,mid+1,r,left,right);
}
long long count_rectangles(std::vector<std::vector<int> > a) {
grid=a;
int n=a.size();
if(n<=2){
return 0;
}
int m=a[0].size();
int ans=0;
for (int i = 0; i < m; ++i)
{
if(grid[1][i]>=grid[0][i]||grid[1][i]>=grid[2][i]) tab[i]=true;
else tab[i]=0;
}
build1(0,0,m-1);
build(0,0,m-1);
for (int i = 1; i < m-1; ++i)
{
for (int j = i; j < m-1; ++j)
{
int cur=query(0,0,m-1,i,j);
//cout <<i<<" "<<j<<" "<<cur<<endl;
if(cur>=a[1][i-1]||cur>=a[1][j+1]) continue;
cur=query1(0,0,m-1,i,j);
if(cur==1) continue;
ans++;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
353 ms |
616 KB |
Output is correct |
2 |
Correct |
248 ms |
600 KB |
Output is correct |
3 |
Correct |
342 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Incorrect |
370 ms |
604 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
321 ms |
39820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |