Advertisement
a53

cutting

a53
Feb 2nd, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. # include <bits/stdc++.h>
  2. using namespace std;
  3. map <long long,long long> mp;
  4. long long S;
  5. long long m,n;
  6.  
  7. long long calcArea(pair <long long,long long> A,pair <long long,long long> B)
  8. {
  9.  
  10. long long x=(B.first+B.second+A.first-A.second);
  11. long long y= x+2*A.second-2*A.first;
  12. long long S=0;
  13. if(y<=2*m)
  14. {
  15. S+=(y+2*A.second)*(x-2*A.first);
  16. S+=(2*B.second+y)*(2*B.first-x);
  17. }
  18. else
  19. {
  20. long long x1=m+A.first-A.second;
  21. long long x2=B.second+B.first-m;
  22. S+=(m+A.second)*(x1-A.first);
  23. S+=2*(x2-x1)*m;
  24. S+=(m+B.second)*(B.first-x2);
  25. S=S*4;
  26. }
  27. return S;
  28. }
  29.  
  30. bool isPointUp(pair <long long,long long> P,pair <long long,long long> A,pair <long long,long long> B)
  31. {
  32. pair <long long,long long> v1;
  33. v1.first=B.first-A.first;
  34. v1.second=B.second-A.second;
  35. pair <long long,long long> v2;
  36. v2.first=P.first-A.first;
  37. v2.second=P.second-A.second;
  38. long long cross=v1.first*v2.second-v1.second*v2.first;
  39. return cross>=0;
  40. }
  41.  
  42. void update(long long x,long long y)
  43. {
  44. auto itr=mp.lower_bound(x);
  45. if(itr->first>=x&&x!=0)
  46. --itr;
  47. auto nextt=itr;
  48. ++nextt;
  49. S-=calcArea(*itr,*nextt);
  50. auto curr=itr;
  51. if(itr->first>0)
  52. {
  53. --curr;
  54. while(1)
  55. {
  56. if(isPointUp(*itr,{x-1,y+1},{x,y}))
  57. {
  58. S -= calcArea(*curr,*itr);
  59. mp.erase(itr);
  60. itr = curr;
  61. if(itr->first==0)
  62. break;
  63. --curr;
  64. }
  65. else
  66. break;
  67. }
  68. }
  69. if(itr->first==0)
  70. itr->second=min(itr->second,x+y);
  71. auto f=itr;
  72. itr=nextt;
  73. if(itr->first!=n)
  74. {
  75. ++nextt;
  76. while(1)
  77. {
  78. if(isPointUp(*itr,{x,y},{x+1,y+1}))
  79. {
  80. S-=calcArea(*itr,*nextt);
  81. mp.erase(itr);
  82. itr=nextt;
  83. if(itr->first==n)
  84. break;
  85. ++nextt;
  86. }
  87. else
  88. break;
  89. }
  90. }
  91. if(itr->first==n)
  92. {
  93. itr->second=min(itr->second,n+y-x);
  94. }
  95. auto l=itr;
  96. mp[x]=y;
  97. itr=mp.find(x);
  98. S+=calcArea(*f,*itr);
  99. S+=calcArea(*itr,*l);
  100. }
  101.  
  102. void init(long long N,long long M)
  103. {
  104. n=N;
  105. m=M;
  106. mp[0]=m;
  107. mp[n]=m;
  108. S=calcArea({0,m},{n,m});
  109. }
  110.  
  111. int main()
  112. {
  113. ios_base::sync_with_stdio(false);
  114. cin.tie(nullptr);
  115. long long N,M;
  116. cin>>N>>M;
  117. init(N,M);
  118. long long Q;
  119. cin>>Q;
  120. long long x,y;
  121. while(Q--)
  122. {
  123. cin>>x>>y;
  124. update(x,y);
  125. double p=(double)S/8;
  126. printf("%.2f\n",p);
  127. }
  128. return 0;
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement