Submission #836359

#TimeUsernameProblemLanguageResultExecution timeMemory
836359AntekbRectangles (IOI19_rect)C++17
72 / 100
5093 ms300000 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=1e5+5; ll count_rectangles(std::vector<std::vector<int> > tab) { int n=tab.size(), m=tab[0].size(); vector<vector<vi>> par(n, vector<vi>(m)); for(int i=1; i<m-1; i++){ vi V={0}; for(int j=1; j<n; j++){ while(V.size() && tab[j][i]>tab[V.back()][i]){ if(V.back()!=j-1)par[j][i].pb(V.back()); V.pp(); } if(V.size() && V.back()!=j-1)par[j][i].pb(V.back()); if(V.size() && tab[V.back()][i]==tab[j][i])V.pp(); V.pb(j); } } 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; for(int r=1; r<n-1; r++){ 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); for(int i=0; i<akt.size(); i++){ //deb(r, i, akt[i].st, akt[i].nd, dp[i]); for(int l=akt[i].st+1; l<akt[i].nd; l++){ wsk2[l]=0; } for(int k=r-1; k>=r-dp[i]; k--){ bool b=1; for(int l=akt[i].st+1; l<akt[i].nd; l++){ while(wsk2[l]<par[r+1][l].size() && par[r+1][l][wsk2[l]]>k){ wsk2[l]++; } if(wsk2[l]==par[r+1][l].size() || par[r+1][l][wsk2[l]]!=k){ //deb(k, l, wsk2[l], par[r+1][l].size()); b=0; break; } } if(b){ //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:47:12: warning: unused variable 'k' [-Wunused-variable]
   47 |    for(int k:par[i][j]){
      |            ^
rect.cpp:74: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]
   74 |   for(int i=0; i<akt.size(); i++){
      |                ~^~~~~~~~~~~
rect.cpp:75: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]
   75 |    while(wsk<prv.size() && (akt[i].st<prv[wsk].st
      |          ~~~^~~~~~~~~~~
rect.cpp:77: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]
   77 |    if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk];
      |       ~~~^~~~~~~~~~~
rect.cpp:80: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]
   80 |   for(int i=0; i<akt.size(); i++){
      |                ~^~~~~~~~~~~
rect.cpp:88:19: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |      while(wsk2[l]<par[r+1][l].size() && par[r+1][l][wsk2[l]]>k){
rect.cpp:91:16: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |      if(wsk2[l]==par[r+1][l].size() || par[r+1][l][wsk2[l]]!=k){
#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...