제출 #969301

#제출 시각아이디문제언어결과실행 시간메모리
969301NemanjaSo2005Rectangles (IOI19_rect)C++17
100 / 100
4160 ms589064 KiB
#include "rect.h" #include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=2505; ll res=0; int N,M; int L[maxn],R[maxn]; stack<int> S; map<pair<int,int>,int> mapa[maxn]; vector<pair<int,int>> getinterval(vector<int> &V){ vector<pair<int,int>> res; while(S.size()) S.pop(); S.push(0); L[0]=-1; for(int i=1;i<V.size();i++){ while(S.size()){ if(V[S.top()]>V[i]) break; S.pop(); } if(S.size()==0) L[i]=-1; else L[i]=S.top()+1; S.push(i); } while(S.size()) S.pop(); S.push(V.size()-1); for(int i=V.size()-2;i>=1;i--){ while(S.size()){ if(V[S.top()]>V[i]) break; S.pop(); } if(S.size()==0) R[i]=-1; else R[i]=S.top()-1; S.push(i); } for(int i=1;i<V.size()-1;i++){ if(L[i]==-1) continue; if(R[i]==-1) continue; res.push_back({L[i],R[i]}); } vector<pair<int,int>> r2; if(res.size()){ sort(res.begin(),res.end()); r2.push_back(res[0]); for(int i=1;i<res.size();i++) if(res[i]!=res[i-1]) r2.push_back(res[i]); } res.clear(); res.shrink_to_fit(); return r2; } struct slog3{ int duz,kol,poz; }spp; vector<slog3> vert[maxn]; struct slog{ int duz,kol; } pp; bool poduz(slog a,slog b){ return a.duz<b.duz; } bool pokol(slog a,slog b){ return a.kol<b.kol; } int fwt[maxn]; void add(int x,int kol){ x++; for(int i=x;i<=2501;i+=i&-i) fwt[i]+=kol; } int sum(int x){ int r=0; x++; for(int i=x;i>=1;i-=i&-i) r+=fwt[i]; return r; } int resi(vector<slog> &A,vector<slog> &B){ int ret=0; swap(A,B); sort(B.begin(),B.end(),pokol); for(int i=0;i<B.size();i++) add(B[i].duz,1); int pok=0; for(int i=0;i<A.size();i++){ while(pok<B.size()){ if(B[pok].kol>=A[i].duz) break; add(B[pok].duz,-1); pok++; } ret+=sum(A[i].kol); } while(pok<B.size()){ add(B[pok].duz,-1); pok++; } return ret; } ll count_rectangles(std::vector<std::vector<int> > inp) { N=inp.size(); M=inp[0].size(); /// Vertikalni for(int i=N-2;i>=1;i--){ vector<int> V; for(int j=0;j<M;j++) V.push_back(inp[i][j]); auto I = getinterval(V); V.clear(); V.shrink_to_fit(); for(auto x:I){ int v; if(mapa[i+1].find(x)!=mapa[i+1].end()){ v=mapa[i+1][x]+1; mapa[i][x]=v; } else{ v=1; mapa[i][x]=1; } spp.kol=v; spp.duz=x.second-x.first+1; spp.poz=i; vert[x.first].push_back(spp); } } /// Horizontalni ll res=0; for(int i=0;i<=M;i++) mapa[i].clear(); for(int i=0;i<=M;i++) mapa[i].clear(); for(int i=M-2;i>=1;i--){ int pok=0; reverse(vert[i].begin(),vert[i].end()); /*cout<<i<<":"<<endl; for(auto x:vert[i]) cout<<x.poz<<" "; cout<<endl;*/ vector<int> V; for(int j=0;j<N;j++) V.push_back(inp[j][i]); auto I = getinterval(V); if(I.size()==0) continue; vector<slog> PV; V.clear(); V.shrink_to_fit(); int px=I[0].first; for(auto x:I){ if(x.first!=px){ vector<slog> V; while(pok<vert[i].size()){ if(vert[i][pok].poz>px) break; if(vert[i][pok].poz==px){ pp.duz=vert[i][pok].duz; pp.kol=vert[i][pok].kol; V.push_back(pp); } pok++; } res+=resi(V,PV); px=x.first; PV.clear(); } int v; if(mapa[i+1].find(x)!=mapa[i+1].end()){ v=mapa[i+1][x]+1; mapa[i][x]=v; } else{ v=1; mapa[i][x]=1; } pp.kol=v; pp.duz=x.second-x.first+1; PV.push_back(pp); } vector<slog> VV; while(pok<vert[i].size()){ if(vert[i][pok].poz>px) break; if(vert[i][pok].poz==px){ pp.duz=vert[i][pok].duz; pp.kol=vert[i][pok].kol; VV.push_back(pp); } pok++; } res+=resi(VV,PV); } return res; }

컴파일 시 표준 에러 (stderr) 메시지

rect.cpp: In function 'std::vector<std::pair<int, int> > getinterval(std::vector<int>&)':
rect.cpp:17:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |    for(int i=1;i<V.size();i++){
      |                ~^~~~~~~~~
rect.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    for(int i=1;i<V.size()-1;i++){
      |                ~^~~~~~~~~~~
rect.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |       for(int i=1;i<res.size();i++)
      |                   ~^~~~~~~~~~~
rect.cpp: In function 'int resi(std::vector<slog>&, std::vector<slog>&)':
rect.cpp:97:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slog>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |    for(int i=0;i<B.size();i++)
      |                ~^~~~~~~~~
rect.cpp:101:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slog>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |    for(int i=0;i<A.size();i++){
      |                ~^~~~~~~~~
rect.cpp:102:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slog>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |       while(pok<B.size()){
      |             ~~~^~~~~~~~~
rect.cpp:111:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slog>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |    while(pok<B.size()){
      |          ~~~^~~~~~~~~
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:176:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slog3>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  176 |             while(pok<vert[i].size()){
      |                   ~~~^~~~~~~~~~~~~~~
rect.cpp:208:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slog3>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  208 |       while(pok<vert[i].size()){
      |             ~~~^~~~~~~~~~~~~~~
#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...