Tranvick

Untitled

Jan 9th, 2012
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #pragma comment(linker, "/STACK:65777216")
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <cstdio>
  7. #include <algorithm>
  8. #include <cmath>
  9. #include <vector>
  10. #include <set>
  11. #include <stack>
  12. #include <map>
  13. #include <queue>
  14. #include <string>
  15. #include <memory.h>
  16. #include <iterator>
  17. #define mem(A,X) memset(A,X,sizeof(A))
  18. #define memo(A) memset(A,0,sizeof(A))
  19. #define forn(I,B) for (int I=1;I<=(B);I++)
  20. #define forg(H,V) for (int H=first[V];h;h=next[H])
  21. #define rep(I,B) for (int I=0;I<(B);I++)
  22. #define labs(X) (((X)>0)?(X):(-(X)))
  23. #define ropen(X) freopen(X,"r",stdin)
  24. #define wopen(X) freopen(X,"w",stdout)
  25. #define pb push_back
  26. #define mp make_pair
  27. #define all(X) (X).begin(),(X).end()
  28. #define sqr(X) ((X)*(X))
  29.  
  30. using namespace std;
  31.  
  32. typedef pair <int,int> pii;
  33. typedef pair <long long,long long> pll;
  34. typedef double ld;
  35. typedef long long ll;
  36. typedef vector<int> vi;
  37. const int N=111111;
  38. const int INF=111111111;
  39. const double eps=1e-9;
  40. const double pi=3.14159265358979;
  41.  
  42. int n,q[N+N],s[N+N],place[N],ans,f[N],g[N+N];
  43.  
  44. void inc(int pos){
  45.     for(;pos<N;pos|=pos-1,++pos) ++f[pos];
  46. }
  47.  
  48. void dec(int pos){
  49.     for(;pos<N;pos|=pos-1,++pos) --f[pos];
  50. }
  51.  
  52. int get(int p){
  53.     int res=0;
  54.     for(;p;p&=p-1) res+=f[p];
  55.     return res;
  56. }
  57.  
  58. struct pass{
  59.     int a,b,c,id;
  60.     bool operator < (const pass & x) const{
  61.         return c<x.c || c==x.c && a>x.a;
  62.     }
  63. } t[N];
  64.  
  65. int main(){
  66.     ropen("taxibus.in");
  67.     wopen("taxibus.out");
  68.     scanf("%d",&n);
  69.     forn(i,n) t[i].id=i;
  70.     forn(i,n){
  71.         scanf("%d%d",&t[i].a,&t[i].b);
  72.         q[t[i].a]=1;
  73.         g[t[i].a]=i;
  74.         g[t[i].b]=-i;
  75.     }
  76.     forn(i,n+n) s[i]=s[i-1]+q[i];
  77.     forn(i,n) t[i].c=s[t[i].b]-s[t[i].a];
  78.     sort(t+1,t+n+1);
  79.     forn(i,n) place[t[i].id]=i;
  80.     forn(i,n+n){
  81.         ans+=get(place[labs(g[i])]-1);
  82.         if (g[i]<0) dec(place[-g[i]]);
  83.         else inc(place[g[i]]);
  84.     }
  85.     printf("%d\n",ans);
  86.     forn(i,n) printf("%d ",place[i]);
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment