iscsi

CF #243 D TLE

Apr 30th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <list>
  7. #include <queue>
  8. #include <set>
  9. #include <map>
  10. #include <cstdio>
  11. #include <cstdlib>
  12. #include <cctype>
  13. #include <cmath>
  14. #include <cstring>
  15. #include <ctime>
  16. #include <cassert>
  17. using namespace std;
  18. typedef long long LL;
  19. #define FOR(k,a,b) for(LL k(a); k < (b); ++k)
  20. #define FORD(k,a,b) for(int k(b-1); k >= (a); --k)
  21. #define REP(k,a) for(int k=0; k < (a); ++k)
  22. #define ABS(a) ((a)>0?(a):-(a))
  23.  
  24. typedef vector<int> VI;
  25. typedef vector<vector<int> > VVI;
  26. typedef vector<bool> VB;
  27. typedef vector<pair<int,int> > VP;
  28.  
  29. int main()
  30. {
  31. #ifdef HOME
  32.     clock_t startclock=clock();
  33.     freopen ("in.txt","r",stdin);
  34.     freopen ("out.txt","w",stdout);
  35.     freopen ("out_err.txt","w",stderr);
  36. #endif
  37.     int n;
  38.     scanf("%d",&n);
  39.     vector<pair<int,int> > points(n);
  40.     REP(i,n)
  41.     {
  42.         scanf("%d %d",&points[i].first,&points[i].second);
  43.     }
  44.     vector<pair<int,int> > p1=points;//x,y
  45.  
  46.     vector<pair<int,int> > p2=points;//y,x
  47.     REP(i,n) swap(p2[i].first,p2[i].second);
  48.  
  49.     vector<pair<int,int> > pdiag=points;//x-y,x
  50.     REP(i,n)
  51.     {
  52.         int x=points[i].first;
  53.         int y=points[i].second;
  54.  
  55.         pdiag[i].first=x-y;
  56.         pdiag[i].second=x;
  57.     }
  58.  
  59.     sort(p1.begin(),p1.end());
  60.     sort(p2.begin(),p2.end());
  61.     sort(pdiag.begin(),pdiag.end());
  62.    
  63.     int res = 0;
  64.  
  65.     REP(i,n)
  66.     {
  67.         int actx = p1[i].first;
  68.         int acty = p1[i].second;
  69.         VP::iterator it1 = p1.begin()+i;
  70.         VP::iterator it2 = find(p2.begin(),p2.end(),make_pair(acty,actx));
  71.         VP::iterator it3 = find(pdiag.begin(),pdiag.end(),make_pair(actx-acty,actx));
  72.  
  73.         pair<int,int> pp;
  74.         pp = make_pair(actx,1e6);
  75.         VP::iterator endit1 = lower_bound(p1.begin(),p1.end(),pp);
  76.         pp = make_pair(acty,1e6);
  77.         VP::iterator endit2 = lower_bound(p2.begin(),p2.end(),pp);
  78.         pp = make_pair(actx-acty,1e6);
  79.         VP::iterator endit3 = lower_bound(pdiag.begin(),pdiag.end(),pp);
  80.         ++it1,++it2,++it3;
  81.        
  82.         while(it1!=endit1 && it2!=endit2 && it3!=endit3)
  83.         {
  84.             if(it1->first>actx) break;
  85.             if(it2->first>acty) break;
  86.             if(it3->first>actx-acty) break;
  87.             int k1 = it1->second-acty;
  88.             int k2 = it2->second-actx;
  89.             int k3 = it3->second-actx;
  90.            
  91.             int maxk = max(max(k1,k2),k3);
  92.             bool ok = 1;
  93.             pp = make_pair(actx,acty+maxk);
  94.             it1 = lower_bound(it1, endit1,pp);
  95.             if(it1 ==  endit1) break;
  96.             if(*it1 != pp) ok=0;
  97.             pp=make_pair(acty,actx+maxk);
  98.             it2 = lower_bound(it2, endit2,pp);
  99.             if(it2 ==  endit2) break;
  100.             if(*it2 != pp) ok=0;
  101.             pp=make_pair(actx-acty,actx+maxk);
  102.             it3 = lower_bound(it3, endit3,pp);
  103.             if(it3 == endit3) break;
  104.             if(*it3 != pp) ok=0;
  105.             if(ok)
  106.             {
  107.                 ++it1,++it2,++it3;
  108.                 ++res;
  109.             }
  110.         }
  111.     }
  112.  
  113.     printf("%d\n",res);
  114.  
  115. #ifdef HOME
  116.     fprintf(stderr,"time=%.3lfsec\n",0.001*(clock()-startclock));
  117. #endif
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment