제출 #823610

#제출 시각아이디문제언어결과실행 시간메모리
823610oscar1fRectangles (IOI19_rect)C++17
59 / 100
5043 ms331468 KiB
#include<bits/stdc++.h> #include "rect.h" using namespace std; using ll=long long; const int TAILLE_MAX=2505,DECA=(1<<12); ll rep; int nbLig,nbCol; int val[TAILLE_MAX][TAILLE_MAX]; int limite[TAILLE_MAX][TAILLE_MAX][4]; int limCalc[TAILLE_MAX][2]; int arbreMin[TAILLE_MAX][2*DECA],arbreMax[TAILLE_MAX][2*DECA]; vector<int> possi; set<int> enCours; set<int>::iterator it; int calcMin(int tab,int deb,int fin) { if (deb==fin) { return arbreMin[tab][deb]; } if (deb%2==1) { return min(arbreMin[tab][deb],calcMin(tab,deb+1,fin)); } if (fin%2==0) { return min(arbreMin[tab][fin],calcMin(tab,deb,fin-1)); } return calcMin(tab,deb/2,fin/2); } int calcMax(int tab,int deb,int fin) { if (deb==fin) { return arbreMax[tab][deb]; } if (deb%2==1) { return max(arbreMax[tab][deb],calcMax(tab,deb+1,fin)); } if (fin%2==0) { return max(arbreMax[tab][fin],calcMax(tab,deb,fin-1)); } return calcMax(tab,deb/2,fin/2); } void calc(int ligHaut,int ligBas,int colGau,int colDroi) { //cout<<ligHaut<<" "<<ligBas<<" "<<colGau<<" "<<colDroi<<" : "; for (int i=colGau-1;i<=colDroi+1;i++) { limCalc[i][0]=calcMax(i,DECA+ligHaut,DECA+ligBas); limCalc[i][1]=calcMin(i,DECA+ligHaut,DECA+ligBas); //cout<<i<<" "<<limCalc[i][0]<<" "<<limCalc[i][1]<<" "; } //cout<<endl; for (int i=colGau;i<=colDroi;i++) { for (int j=i;j<=colDroi;j++) { if (limCalc[i-1][1]>=j and limCalc[j+1][0]<=i) { //cout<<"! "<<ligHaut<<" "<<ligBas<<" "<<i<<" "<<j<<endl; rep++; } } } } ll count_rectangles(vector<vector<int>> a) { nbLig=a.size(); nbCol=a[0].size(); if (nbLig<=2 or nbCol<=2) { return 0; } for (int i=0;i<nbLig;i++) { for (int j=0;j<nbCol;j++) { val[i][j]=a[i][j]; } } for (int i=0;i<nbLig;i++) { enCours.clear(); enCours.insert(-1); possi.clear(); for (int j=0;j<nbCol;j++) { possi.push_back(j); } sort(possi.begin(),possi.end(),[&](int a,int b) { if (val[i][a]>val[i][b]) { return true; } if (val[i][a]<val[i][b]) { return false; } return a<b; }); for (int j:possi) { it=enCours.upper_bound(j); it--; limite[i][j][0]=(*it)+1; //cout<<i<<" "<<j<<" : "<<limite[i][j][0]<<endl; enCours.insert(j); } enCours.clear(); enCours.insert(nbCol); sort(possi.begin(),possi.end(),[&](int a,int b) { if (val[i][a]>val[i][b]) { return true; } if (val[i][a]<val[i][b]) { return false; } return a>b; }); for (int j:possi) { it=enCours.upper_bound(j); limite[i][j][1]=(*it)-1; //cout<<i<<" "<<j<<" : "<<limite[i][j][0]<<endl; enCours.insert(j); } } int deb,pos; for (int i=0;i<nbLig;i++) { for (int j=0;j<nbCol;j++) { pos=i; while (pos>0 and val[i][j]>val[pos-1][j]) { pos--; } limite[i][j][2]=pos; pos=i; while (pos<nbLig-1 and val[i][j]>val[pos+1][j]) { pos++; } limite[i][j][3]=pos; //cout<<i<<" "<<j<<" : "<<limite[i][j][0]<<" "<<limite[i][j][1]<<endl; } } for (int i=0;i<nbCol;i++) { for (int j=0;j<2*DECA;j++) { arbreMin[i][j]=nbCol-1; arbreMax[i][j]=0; } for (int j=0;j<nbLig;j++) { arbreMin[i][DECA+j]=limite[j][i][1]; arbreMax[i][DECA+j]=limite[j][i][0]; } for (int j=DECA-1;j>0;j--) { arbreMin[i][j]=min(arbreMin[i][2*j],arbreMin[i][2*j+1]); arbreMax[i][j]=max(arbreMax[i][2*j],arbreMax[i][2*j+1]); } } for (int ligHaut=1;ligHaut<nbLig-1;ligHaut++) { for (int ligBas=ligHaut;ligBas<nbLig-1;ligBas++) { pos=1; while (pos<nbCol-1) { deb=pos; while (pos<nbCol-1 and limite[ligHaut-1][pos][3]>=ligBas and limite[ligBas+1][pos][2]<=ligHaut) { pos++; } if (pos>deb) { calc(ligHaut,ligBas,deb,pos-1); } pos++; } } } return rep; }
#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...