Submission #836440

#TimeUsernameProblemLanguageResultExecution timeMemory
836440AntekbRectangles (IOI19_rect)C++17
100 / 100
1848 ms89168 KiB
#include<bits/stdc++.h> #include "rect.h" #define st first #define nd second #define pb push_back #define eb emplace_back #define pp pop_back #define mp make_pair #define all(x) (x).begin(), (x).end() using namespace std; using pii = pair<int, int>; using vi = vector<int>; using vii = vector<pii>; using ll = long long; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); void debug(){cerr<<"\n";} template<typename H, typename... T> void debug(H h, T... t){ cerr<<h; if(sizeof...(t))cerr<<", "; debug(t...); } #define deb(x...) cerr<<#x<<" = ";debug(x); const int N=2505; ll count_rectangles(std::vector<std::vector<int> > tab) { int n=tab.size(), m=tab[0].size(); if(m<=2 || n<=2)return 0; vector<vi> V2(m, {0}); for(int i=0; i<m; i++){ if(tab[1][i]>=tab[0][i]){ V2[i]={1}; } else V2[i]={0, 1}; } /*for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ //deb(i, j); for(int k:par[i][j]){ //deb(k); } } }*/ vector<pii> prv; vi dp2; ll ans=0; vector<bitset<N> > suf(n); for(int i=0; i<n; i++){ for(int j=i; j<n; j++)suf[i][j]=1; } for(int r=1; r<n-1; r++){ vector<bitset<N>> par(m); for(int i=1; i<m-1; i++){ while(V2[i].size() && tab[r+1][i]>tab[V2[i].back()][i]){ if(V2[i].back()!=r)par[i][V2[i].back()]=1; V2[i].pp(); } if(V2[i].size() && V2[i].back()!=r)par[i][V2[i].back()]=1; if(V2[i].size() && tab[V2[i].back()][i]==tab[r+1][i])V2[i].pp(); V2[i].pb(r+1); } vector<pii> akt; vi dp; vi V={m-1}; for(int j=m-2; j>=0; j--){ while(V.size() && tab[r][j]>tab[r][V.back()]){ if(V.back()!=j+1){ akt.eb(j, V.back()); } V.pp(); } if(V.size() && V.back()!=j+1){ akt.eb(j, V.back()); } if(V.size() && tab[r][V.back()]==tab[r][j])V.pp(); V.pb(j); } dp.resize(akt.size(), 1); int wsk=0; for(int i=0; i<akt.size(); i++){ while(wsk<prv.size() && (akt[i].st<prv[wsk].st || (akt[i].st==prv[wsk].st && akt[i].nd>prv[wsk].nd)))wsk++; if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk]; } vi wsk2(m); vector<int> S; vector<bitset<N> > b(akt.size()); for(int i=0; i<akt.size(); i++){ //deb(r, i, akt[i].st, akt[i].nd, dp[i]); b[i]=suf[0]; //for(int k=r-1; k>=r-dp[i]; k--)b[i][k]=1; int pocz=akt[i].st+1; while(S.size()){ int a=S.back(); if(akt[a].st>=akt[i].nd)break; S.pp(); for(;pocz<=akt[a].st;pocz++){ b[i]&=par[pocz]; } b[i]&=b[a]; pocz=akt[a].nd; } S.pb(i); /*for(int j=0; j<i; j++){ if(akt[i].nd>=akt[j].nd){ assert(dp[i]<=dp[j]); b[i]&=b[j]; } }*/ for(;pocz<akt[i].nd;pocz++){ b[i]&=par[pocz]; } ans+=(b[i]&suf[r-dp[i]]).count(); /*for(int k=r-1; k>=r-dp[i]; k--){ if(b[i][k]){ //deb(r, akt[i].st, akt[i].nd, k); ans++; } }*/ } prv=akt; dp2=dp; } return ans; }

Compilation message (stderr)

rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:83:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for(int i=0; i<akt.size(); i++){
      |                ~^~~~~~~~~~~
rect.cpp:84:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |    while(wsk<prv.size() && (akt[i].st<prv[wsk].st
      |          ~~~^~~~~~~~~~~
rect.cpp:86:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |    if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk];
      |       ~~~^~~~~~~~~~~
rect.cpp:91:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |   for(int i=0; i<akt.size(); i++){
      |                ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...