I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! I AK IOI! #include <cstdlib> #include <fstream> #include <iostream> #include <sstream> #include <string> using namespace std; bool readInt(istream &file, long long &value) { string token; if (!(file >> token)) return false; istringstream number(token); return (number >> value) && number.eof(); } int main(int argc, char **argv) { if (argc != 4) { cerr << "Usage: checker infile outfile ansfile\n"; return 2; } ifstream input(argv[1]), output(argv[2]), answer(argv[3]); int n, m; long long w, h, best; if (!(input >> n >> m >> w >> h) || n < 1 || n > 100000 || m < 1 || m > 100000 || w < 1 || w > 1000000000 || h < 1 || h > 1000000000 || !readInt(answer, best) || best < 0 || best > (n > m ? n : m)) { cerr << "Invalid input or answer file\n"; return 2; } long long reported, a, b; string extra; if (!readInt(output, reported) || !readInt(output, a) || !readInt(output, b) || (output >> extra)) { cerr << "Expected exactly three integers: difference, a, b\n"; return 1; } if (reported != best) { cerr << "Wrong maximum difference: expected " << best << ", got " << reported << '\n'; return 1; } int red = 0, blue = 0; for (int i = 0; i < n + m; ++i) { long long x, y; if (!(input >> x >> y) || x < 1 || x > 1000000000 || y < 1 || y > 1000000000) { cerr << "Invalid point in input file\n"; return 2; } if (x - w <= a && a <= x && y - h <= b && b <= y) { if (i < n) ++red; else ++blue; } } if (abs(red - blue) != best) { cerr << "Rectangle contains " << red << " red and " << blue << " blue points, giving difference " << abs(red - blue) << " instead of " << best << '\n'; return 1; } return 0; } setlocal enabledelayedexpansion for %%A in ("%cd%") do set "WORKDIR=%%~nxA" @REM if defined clang_cfg ( @REM @REM call %~dp0zipcode || pause @REM call %~dp0compile_clang++ || pause @REM ) else ( call %~dp0compile_g++ || pause @REM ) for %%e in (*.exe) do if not %%e==checker.exe ( for /f %%f in ('dir /b /on ^|findstr \.in$') do if not %%f==!WORKDIR!.in if %%~zf gtr 0 ( copy /y "%%f" "!WORKDIR!.in" echo No Write In > "!WORKDIR!.out" copy /y "%%~nf.ans" "!WORKDIR!.ans" ts || pause "%%e" || pause te || pause if exist checker.exe ( checker "!WORKDIR!.in" "!WORKDIR!.out" "!WORKDIR!.ans" || pause ) else ( fc /w "!WORKDIR!.out" "!WORKDIR!.ans" || pause ) ) ) echo PASS! @REM pause #include<bits/stdc++.h> using namespace std; struct node{ long long x,l,r; int v; bool operator<(const node &a)const{ return x<a.x; } }q[800005]; long long y[800005],w,h,ans1,ans2; int n,m,cnt,len,ans=-1; int mx[3200005],tag[3200005]; void add(int p,int l,int r,int x,int z,int v){ if(x<=l&&r<=z){ mx[p]+=v; tag[p]+=v; return; } int mid=(l+r)/2; if(x<=mid)add(p*2,l,mid,x,z,v); if(z>mid)add(p*2+1,mid+1,r,x,z,v); mx[p]=max(mx[p*2],mx[p*2+1])+tag[p]; } int ask(int p,int l,int r){ if(l==r)return l; int mid=(l+r)/2; if(mx[p*2]>=mx[p*2+1])return ask(p*2,l,mid); return ask(p*2+1,mid+1,r); } void ins(long long x,long long yy,int v){ q[++cnt]={x-w,yy-h,yy,v}; q[++cnt]={x+1,yy-h,yy,-v}; y[++len]=yy-h; y[++len]=yy+1; } int main(){ freopen("redblue.in","r",stdin); freopen("redblue.out","w",stdout); cin>>n>>m>>w>>h; for(long long i=1;i<=n+m;i++){ long long x,yy; cin>>x>>yy; ins(x,yy,i<=n?1:-1); } sort(q+1,q+cnt+1); sort(y+1,y+len+1); len=unique(y+1,y+len+1)-y-1; for(int i=1;i<=cnt;){ int j=i; while(j<=cnt&&q[j].x==q[i].x){ int l=lower_bound(y+1,y+len+1,q[j].l)-y; int r=lower_bound(y+1,y+len+1,q[j].r+1)-y-1; if(l<=r)add(1,1,len,l,r,q[j].v); j++; } if(mx[1]>ans){ ans=mx[1]; ans1=q[i].x; ans2=y[ask(1,1,len)]; } i=j; } cout<<ans<<"\n"; cout<<ans1<<" "<<ans2<<"\n"; return 0; } /* 3 3 4 4 1 1 2 2 3 3 1 3 3 1 4 4 */ //// #include<bits/stdc++.h> using namespace std; struct node{ long long x,l,r; int v; bool operator<(const node &a)const{ return x<a.x; } }q[800005]; long long y[800005],w,h,ans1,ans2; int n,m,cnt,len,ans=-1; int mx[3200005],mn[3200005],tag[3200005]; void add(int p,int l,int r,int x,int z,int v){ if(x<=l&&r<=z){ mx[p]+=v; mn[p]+=v; tag[p]+=v; return; } int mid=(l+r)/2; if(x<=mid)add(p*2,l,mid,x,z,v); if(z>mid)add(p*2+1,mid+1,r,x,z,v); mx[p]=max(mx[p*2],mx[p*2+1])+tag[p]; mn[p]=min(mn[p*2],mn[p*2+1])+tag[p]; } int ask(int p,int l,int r,bool useMax){ if(l==r)return l; int mid=(l+r)/2; bool left=useMax?mx[p*2]>=mx[p*2+1]:mn[p*2]<=mn[p*2+1]; if(left)return ask(p*2,l,mid,useMax); return ask(p*2+1,mid+1,r,useMax); } void ins(long long x,long long yy,int v){ q[++cnt]={x-w,yy-h,yy,v}; q[++cnt]={x+1,yy-h,yy,-v}; y[++len]=yy-h; y[++len]=yy+1; } int main(){ freopen("redblue.in","r",stdin); freopen("redblue.out","w",stdout); cin>>n>>m>>w>>h; for(long long i=1;i<=n+m;i++){ long long x,yy; cin>>x>>yy; ins(x,yy,i<=n?1:-1); } sort(q+1,q+cnt+1); sort(y+1,y+len+1); len=unique(y+1,y+len+1)-y-1; for(int i=1;i<=cnt;){ int j=i; while(j<=cnt&&q[j].x==q[i].x){ int l=lower_bound(y+1,y+len+1,q[j].l)-y; int r=lower_bound(y+1,y+len+1,q[j].r+1)-y-1; if(l<=r)add(1,1,len,l,r,q[j].v); j++; } int now=max(mx[1],-mn[1]); if(now>ans){ ans=now; ans1=q[i].x; ans2=y[ask(1,1,len,mx[1]>=-mn[1])]; } i=j; } cout<<ans<<"\n"; cout<<ans1<<" "<<ans2<<"\n"; return 0; } /* 3 3 4 4 1 1 2 2 3 3 1 3 3 1 4 4 */
Note.ms
/akioi