제출 #197548

#제출 시각아이디문제언어결과실행 시간메모리
197548SamAndPairs (IOI07_pairs)C++17
55 / 100
4096 ms257524 KiB
#include <bits/stdc++.h> using namespace std; const int N=100005,M=75; int b,n,d,m; ////////////////////////////////// void so1() { int a[N]; for(int i=0;i<n;++i) { scanf("%d",&a[i]); } sort(a,a+n); long long ans=0; int j=-1; for(int i=0;i<n;++i) { while(1) { if((a[i]-a[j+1])<=d) break; ++j; } ans+=(i-j-1); } cout<<ans<<endl; } ////////////////////////////////// ////////////////////////////////// struct ban { int x,y; }; bool operator<(const ban& a,const ban& b) { if(a.x<b.x) return true; if(a.x>b.x) return false; return a.y<b.y; } map<int,int> t[M*1000*4]; void ubd_f(int pos,int y) { while(y<=m+m) { t[pos][y]++; y+=(y&(-y)); } } int qry_f(int pos,int y) { int ans=0; while(y>=1) { if(t[pos].find(y)!=t[pos].end()) ans+=t[pos][y]; y-=(y&(-y)); } return ans; } void ubd_t(int tl,int tr,int x,int y,int pos) { ubd_f(pos,y); if(tl==tr) return; int mid=(tl+tr)/2; if(x<=mid) ubd_t(tl,mid,x,y,pos*2); else ubd_t(mid+1,tr,x,y,pos*2+1); } long long qry_t(int tl,int tr,int l,int r,int y,int pos) { if(l>r) return 0; if(tl==l && tr==r) return qry_f(pos,m+m)-qry_f(pos,y-1); int mid=(tl+tr)/2; return qry_t(tl,mid,l,min(r,mid),y,pos*2)+qry_t(mid+1,tr,max(l,mid+1),r,y,pos*2+1); } void so2() { ban a[N]; for(int i=0;i<n;++i) scanf("%d%d",&a[i].x,&a[i].y); sort(a,a+n); long long ans=0; for(int i=0;i<n;++i) { if(a[i].x+a[i].y-d<=m+m) ans+=qry_t(1,m,1,a[i].y,max(a[i].x+a[i].y-d,1),1); ubd_t(1,m,a[i].y,a[i].x+a[i].y,1); } for(int i=0;i<=m*4;++i) t[i].clear(); for(int i=0;i<n;++i) { if(a[i].x-a[i].y-d+m<=m+m) ans+=qry_t(1,m,a[i].y+1,m,max(a[i].x-a[i].y-d+m,1),1); ubd_t(1,m,a[i].y,a[i].x-a[i].y+m,1); } cout<<ans<<endl; } ////////////////////////////////// ////////////////////////////////// void sot() { int a[N][3]; for(int i=0;i<n;++i) { for(int j=0;j<b;++j) scanf("%d",&a[i][j]); } long long ans=0; for(int i=0;i<n;++i) { for(int j=0;j<i;++j) { int yd=0; for(int k=0;k<b;++k) { yd+=abs(a[i][k]-a[j][k]); } if(yd<=d) ++ans; } } cout<<ans<<endl; } ////////////////////////////////// int main() { scanf("%d%d%d%d",&b,&n,&d,&m); if(b==1) so1(); if(b==2) so2(); if(b==3) sot(); return 0; }

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

pairs.cpp: In function 'int main()':
pairs.cpp:150:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(b==3)
     ^~
pairs.cpp:152:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  return 0;
  ^~~~~~
pairs.cpp: In function 'void so1()':
pairs.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
pairs.cpp: In function 'void so2()':
pairs.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a[i].x,&a[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp: In function 'void sot()':
pairs.cpp:123:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&a[i][j]);
             ~~~~~^~~~~~~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:145:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d",&b,&n,&d,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...
#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...