제출 #291183

#제출 시각아이디문제언어결과실행 시간메모리
291183thebesRectangles (IOI19_rect)C++14
72 / 100
5152 ms782920 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define F first #define S second const int MN = 2505, MM = 13e6; int N, M, C, i, j, x, y, h[MM], hp[MM], cnt, pre[MN], ds[MN], nxt[MN]; ll ans; pii bnd[MM]; vi vec[MN], adj[MM], hid[MN]; map<pii,int> id; queue<pii> q[MN]; vector<pii> evt[MN]; pii hist[MN][MN]; inline void add(int l,int r,int pid,int x,bool col){ if(l==-1||r==-1) return; if(!id.count({l,r})){ if(col){ id[{l,r}]=1; evt[r-1].push_back({x,l+1}); } else{ id[{l,r}]=++cnt; bnd[cnt] = {l+1,r-1}; h[cnt] = x; if(pid!=-1){ adj[cnt].push_back(pid); hp[pid] = 1; } } q[r-l].push({l,r}); } else if(!col){ if(pid!=-1){ adj[id[{l,r}]].push_back(pid); hp[pid] = 1; } } } pii stk[MN]; int tp; inline void process(vi vec,int x,bool col){ C = (int)vec.size(); tp = -1; for(int i=C-1;i>=0;i--){ while(tp>=0){ if(stk[tp].F<=vec[i]) tp--; else break; } if(tp>=0) nxt[i]=stk[tp].S; else nxt[i]=-1; stk[++tp]={vec[i],i}; } tp = -1; for(int i=0;i<C;i++){ while(tp>=0){ if(stk[tp].F<=vec[i]) tp--; else break; } if(tp>=0) pre[i]=stk[tp].S; else pre[i]=-1; stk[++tp]={vec[i],i}; } id.clear(); vector<pii> tmp; for(int i=1;i<C-1;i++){ int l = pre[i], r = nxt[i]; if(l!=-1&&r!=-1) tmp.push_back({l,r}); } sort(tmp.begin(),tmp.end(),[](pii i,pii j){return i.S-i.F<j.S-j.F;}); int cur = 0; for(int i=0;i<=C;i++){ while(cur<tmp.size()&&tmp[cur].S-tmp[cur].F==i){ add(tmp[cur].F,tmp[cur].S,-1,x,col); cur++; } while(q[i].size()){ pii cur = q[i].front(); q[i].pop(); int l, r; if(vec[cur.F]==vec[cur.S]) l = pre[cur.F], r = nxt[cur.S]; else if(vec[cur.F]<vec[cur.S]) l = pre[cur.F], r = cur.S; else l = cur.F, r = nxt[cur.S]; add(l,r,id[cur],x,col); } } } vi res; inline void mrg(int x,int y){ if(x^y){ res.clear(); if(vec[x].size()>vec[y].size()) swap(x,y); for(int i=0,j=0;i<(int)vec[x].size();i++){ while(j+1<(int)vec[y].size()&&vec[y][j]<vec[x][i]) j++; if(j<vec[y].size()&&vec[x][i]==vec[y][j]) res.push_back(vec[x][i]); } vec[min(x,y)].clear(); vec[max(x,y)]=res; } } int fnd(int x){return ds[x]=ds[x]==x?x:fnd(ds[x]);} void dfs(int n){ for(auto v : adj[n]) dfs(v); for(auto v : adj[n]) mrg(bnd[v].S, bnd[n].S); int it = fnd(bnd[n].F); while(it<M&&it<=bnd[n].S){ mrg(it,bnd[n].S); ds[fnd(it)]=fnd(it+1); it = fnd(it); } int p = upper_bound(vec[bnd[n].S].begin(),vec[bnd[n].S].end(),h[n])-vec[bnd[n].S].begin(); ans += vec[bnd[n].S].size()-p; } long long count_rectangles(vector<vector<int>> a){ vi col; N = a.size(), M = a[0].size(); for(i=0;i<M;i++){ col.clear(); for(j=0;j<N;j++) col.push_back(a[j][i]); process(col,i,1); } for(i=0;i<N;i++) process(a[i],i,0); for(i=1;i<=cnt;i++){ hid[h[i]].push_back(i); } memset(hist,-1,sizeof(hist)); for(i=0;i<N;i++){ for(j=0;j<M;j++) vec[j].clear(), ds[j]=j; for(auto v : evt[i]) vec[v.F].push_back(v.S); for(j=0;j<M;j++) sort(vec[j].begin(),vec[j].end()); for(auto v : hid[i]){ if(hist[bnd[v].F][bnd[v].S].F==i) h[v] = hist[bnd[v].F][bnd[v].S].S+1; else h[v] = 1; hist[bnd[v].F][bnd[v].S]={i+1,h[v]}; h[v] = i-h[v]; } for(auto v : hid[i]){ if(hp[v]) continue; dfs(v); } } return ans; }

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

rect.cpp: In function 'void process(vi, int, bool)':
rect.cpp:77:18: 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 |         while(cur<tmp.size()&&tmp[cur].S-tmp[cur].F==i){
      |               ~~~^~~~~~~~~~~
rect.cpp: In function 'void mrg(int, int)':
rect.cpp:100:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |             if(j<vec[y].size()&&vec[x][i]==vec[y][j]) res.push_back(vec[x][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...