This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18
#define MIN -1e18
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,a,b) for(ll i=b;i>=a;i--)
#define con continue
#define freopen freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628
// typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// template< typename T>
// using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,m,ans,mid,mn,mx,T,sum,h1,h2,e[1234567],b[1234567],c[1234567],d[1<<20],k,i,j,l,r,h,a[1234567],w,x,y,z;
bool used[1234567];
vector<int> v[1234567],vec,vv1,vv2;
string s1,s;
ll sz[1234567],par[1234567],tr[3234567];
ll dx[4]={-1,1,0,0},dy[4]={0,0,-1,1},c1[123][123];
void add(ll x , ll val){
for(x++; x < 2500; x += x & -x) tr[x] += val;
}
ll qry(ll x){
ll res = 0;
for(x++; x; x -= x & -x) res += tr[x];
return res;
}
vector<ll> vv[2][2501];
vector<pl> vp[2];
ll aa[2][2501][2501], lst[2][2501][2501], cnt[2][2501][2501];
ll count_rectangles(vector<vector<int> > vec){
ll n=vec.size();
ll m=vec[0].size();
for(ll i = 0; i < n; i++) vv[0][i].pb(0);
for(ll i = 0; i < m; i++) vv[1][i].pb(0);
ll res = 0;
for(ll i = 0; i < n - 1; i++)
for(ll j = 0; j < m - 1; j++){
aa[0][i][j] = aa[1][j][i] = vec[i][j];
aa[0][i][j + 1] = vec[i][j + 1];
aa[1][j][i + 1] = vec[i + 1][j];
for(ll t = 0; t < 2; t++){
bool ok = 0;
vp[t].clear();
while(!vv[t][i].empty()){
ll c = vv[t][i].back();
if(c < j && !ok){
if(lst[t][c][j + 1] != i - 1) cnt[t][c][j + 1] = 0;
cnt[t][c][j + 1]++ , lst[t][c][j + 1] = i;
vp[t].pb({j - c, cnt[t][c][j + 1]});
if(t) swap(vp[t].back().ff, vp[t].back().ss);
}
ok = aa[t][i][c] == aa[t][i][j + 1];
if(aa[t][i][c] <= aa[t][i][j + 1]) vv[t][i].po();
else break;
}
vv[t][i].pb(j + 1);
swap(i , j);
sort(vp[t].rbegin(), vp[t].rend());
}
ll it = 0;
for(auto u : vp[0]){
for(; it < vp[1].size() && u.ff <= vp[1][it].ff; it++) add(vp[1][it].ss, 1);
res += qry(u.ss);
}
for(ll jt = 0; jt < it; jt++) add(vp[1][jt].ss, -1);
}
return res;
}
Compilation message (stderr)
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:74:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; it < vp[1].size() && u.ff <= vp[1][it].ff; it++) add(vp[1][it].ss, 1);
~~~^~~~~~~~~~~~~~
# | 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... |