이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
vector<bitset<700>> root;
struct tree{
vector<bitset<700>> seg;
void init(int n){
seg.resize(4*n+5);
for(auto &u : seg)
u.flip();
}
void upd(int v, int tl, int tr, int idx, bitset<700> &val){
if(tl == idx && tr == idx){
seg[v] = val;
return;
}
if(idx <= (tl+tr)/2)
upd(2*v, tl, (tl+tr)/2, idx, val);
else
upd(2*v+1, (tl+tr)/2+1, tr, idx, val);
seg[v] = seg[2*v]&seg[2*v+1];
}
int get(int v, int tl, int tr, int val){
if(tl == tr) return tl;
if(seg[2*v][val] == 0)
return get(2*v, tl, (tl+tr)/2, val);
return get(2*v+1, (tl+tr)/2+1, tr, val);
}
};
bitset<700> lef[700][700];
bitset<700> down[700][700];
int n, m;
long long count_rectangles(vector<std::vector<int> > a) {
n = a.size();
m = a[0].size();
for(int i = 0; i < n; ++i){
vector<pii> v;
for(int j = m-1; j >= 0; --j){
while(v.size()){
lef[i][j][v.back().ss] = 1;
if(v.back().ff > a[i][j])
break;
v.pop_back();
}
v.pb({a[i][j], j});
}
}
for(int j = 0; j < m; ++j){
vector<pii> v;
for(int i = n-1; i >= 0; --i){
while(v.size()){
down[i][j][v.back().ss] = 1;
if(v.back().ff > a[i][j])
break;
v.pop_back();
}
v.pb({a[i][j], i});
}
}
ll ans = 0;
for(int i = 1; i < n-1; ++i){
//tree s;
//s.init(m);
for(int j = m-1; j >= 0; --j){
bitset<700> cur;
cur.flip();
for(int k = i; k < n-1; ++k){
cur &= lef[k][j];
//int lim = s.get(1, 0, m, k+1);
bitset<700> oth;
oth.flip();
for(int fin = j+1; fin < m; ++fin){
oth &= down[i-1][fin];
if(fin+1 < m)
ans += oth[k+1]&cur[fin+1];
}
}
//s.upd(1, 0, m, j, down[i-1][j]);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |