fork download
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<math.h>
  4. #include<string.h>
  5. #include<string>
  6. #include<stdlib.h>
  7. #include<map>
  8. #include<vector>
  9. #include<queue>
  10. #include<stack>
  11. #include<algorithm>
  12. #include<set>
  13. using namespace std;
  14.  
  15. // Define Some Variables
  16. #define eps 1e-14
  17. #define si 100010
  18. #define pi acos(-1.0)
  19. #define inf (1<<30)-1
  20. #define mod 1000000000 //10^9
  21.  
  22. //Define Some Functions
  23. #define even(a) ((a)%2==0)
  24. #define odd(a) ((a)%2==1)
  25. #define max(a,b) (a>b ?a:b)
  26. #define min(a,b) (a<b ?a:b)
  27. #define pb push_back
  28. #define mpair make_pair
  29. #define sqr(a)((a)*(a))
  30. #define area(x1,y1,x2,y2,x3,y3) (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) //Area of a triangle
  31. #define dist(x1,y1,x2,y2) (sqr(x1-x2)+sqr(y1-y2)) //Distance between two points
  32. #define mem(a,v) memset(a,v,sizeof(a))
  33. inline bool compare( double a, double b ) { return fabs( a-b ) < eps ; }
  34. #define fr(i,a,b) for(i=a;i<=b;i++)
  35. #define rep(i,a,b) for(i=a;i<b;i++)
  36. #define rev(i,a,b) for(i=a;i>=b;i--)
  37.  
  38. //typedef __int64 i64;
  39. typedef long long i64;
  40.  
  41. int i,j,l,n,cs=1,cnt,sm,fg,a[si];
  42. map<pair<int,int>,int>mp;
  43.  
  44. struct ss
  45. {
  46. int x,y;
  47. }stru[si];
  48.  
  49. bool cmp(ss aa,ss bb)
  50. {
  51. if(aa.x==bb.x)
  52. return aa.y>bb.y;
  53. return aa.x<bb.x;
  54. }
  55.  
  56. int main()
  57. {
  58. // freopen("input.txt", "r", stdin);
  59. // freopen("output.txt", "w", stdout);
  60.  
  61. int m,p,u,v,on,mm,nw,nxt;
  62. scanf("%d%d%d",&n,&m,&p);
  63. //while(~)
  64. //{
  65. for(i=0;i<p;i++)
  66. {
  67. scanf("%d%d",&stru[i].x,&stru[i].y);
  68. mp[make_pair(stru[i].x,stru[i].y)]++;
  69. }
  70.  
  71. for(i=1;i<=n;i++)
  72. a[i]=0;
  73.  
  74. sort(stru,stru+p,cmp);
  75. for(i=0;i<p;i++)
  76. {
  77. nw=mp[make_pair(stru[i].x,stru[i].y)];
  78. nxt=mp[make_pair(stru[i].x,(stru[i].y+1))];
  79. if(nw>(nxt+1)&&stru[i].y<m)
  80. a[stru[i].x]=-1;
  81. }
  82.  
  83. for(i=1;i<=n;i++)
  84. {
  85. if(a[i]<0)
  86. {
  87. printf("-1\n");
  88. continue;
  89. }
  90. sm=m-1;
  91. on=mp[make_pair(i,1)];
  92. mm=mp[make_pair(i,m)];
  93. sm+=(mm-on);
  94.  
  95. printf("%d\n",sm);
  96. }
  97. mp.clear();
  98. //}
  99. return 0;
  100. }
  101.  
Success #stdin #stdout 0s 4652KB
stdin
1 2 1
1 1
stdout
0