版本比较
题解:P11923 [PA 2025] 砖块收集 / Zbieranie klocków
正文
增加 16 行删除 16 行
13 行未改动141516171818192021222324242526272825 行未改动5455565758585960616263646465666768686970717233 行未改动10610710810911011011111211311416 行未改动13113213313413513513613713813911 行未改动15115215315415515615515615715815916011 行未改动17217317417517617617717817918018018118218318430 行未改动21521621721821921922022122222312 行未改动2362372382392402402412422432448 行未改动253254255256257257258259260260261262263264102 行未改动全部展开36736836937037137137237337437511 行未改动13 行未改动```struct cmp1{ bool operator()(node a,node b)const{ auto p=a.first,q=b.first; return p.first==q.first?p.second<q.second:p.first>q.first; return p.first==q.first?p.second<q.second:p.first>q.first; }};struct cmp2{ bool operator()(node a,node b)const{ auto p=a.first,q=b.first; return p.first==q.first?p.second<q.second:p.first<q.first; return p.first==q.first?p.second<q.second:p.first<q.first; }};```这样可以通过自定义比较函数的方式定义 odt。通过存储目前加入过的点的集合方便找到 +1 -1。25 行未改动};struct cmp1{ bool operator()(node a,node b)const{ auto p=a.first,q=b.first; return p.first==q.first?p.second<q.second:p.first>q.first; return p.first==q.first?p.second<q.second:p.first>q.first; }};struct cmp2{ bool operator()(node a,node b)const{ auto p=a.first,q=b.first; return p.first==q.first?p.second<q.second:p.first<q.first; return p.first==q.first?p.second<q.second:p.first<q.first; }};int dis(pair<int,int>a,pair<int,int>b){ return abs(a.first-b.first)+abs(a.second-b.second); return abs(a.first-b.first)+abs(a.second-b.second);}template<class cmp>struct odt{ set<node,cmp>z;33 行未改动 if(!c->ue){ auto fc=*c; z.erase(fc); int res=0; z.insert({f,f,1,1,1,1}); z.insert({f,f,1,1,1,1}); if(fc.first!=f||fc.second!=f){ if(fc.first!=f){ auto w=prev(zc.lower_bound({f}))->first; auto zf=fc;16 行未改动 } z.insert(zf); } } return res; return res; }else if(!c->uc){ auto fc=*c; z.erase(fc); z.insert({f,f,1,1,1,1});11 行未改动 } return -1; }else{ return 0; } }
} int clearmark(pair<int,int>f){ auto c=prev(z.upper_bound({f,f,0,0,0,0})); int res=0;11 行未改动 } } if(next(c)!=z.end()&&dis(next(c)->first,f)==1){ if(!next(c)->uc){
if(next(c)->ue)res-=dis(next(c)->first,next(c)->second)+1; x.second=next(c)->second; x.cntr=next(c)->cntr; z.erase(next(c)); z.erase(next(c)); }else{ x.cntr=1; } }30 行未改动 x.ue=x.uc=0; z.insert(x); } return res;
} size_t size(){ return z.size(); }12 行未改动 return (unsigned long long)f.first<<30|f.second; }};unordered_set<pair<int,int>,has>ff,fz;int zc[5]; int zc[5];#define tot zc[0]#define hap zc[1]void insert1(int x,pair<int,int>y){ hap=hap+cl[x].insert(y);8 行未改动 hap=hap+cr[x].mark(y);}void clearmark1(int x,pair<int,int>y){ hap=hap+cl[x].clearmark(y);} }void clearmark2(int x,pair<int,int>y){ hap=hap+cr[x].clearmark(y);} }void erase1(int x,pair<int,int>y){ hap=hap+cl[x].erase(y);}void erase2(int x,pair<int,int>y){102 行未改动全部展开 cin>>n>>m>>k>>q; map<pair<int,int>,int>tl; for(int i=1;i<=k;i++){ int a,b; cin>>a>>b; cin>>a>>b; tl[{a,b}]=1; adpoint({a,b}); } cout<<tot-hap-fz.size()<<'\n';11 行未改动