Advertisement
ekzolot

Untitled

Feb 12th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. int str(vector<pair<int, int>>& cord, int stolb){
  5. int n=(int) cord.size();
  6. int l=-1;
  7. int r=n;
  8. while(r-l>1){
  9. int m=(l+r)/2;
  10. if (cord[m].first<=stolb){
  11. l=m;
  12. }else{
  13. r=m;
  14. }
  15. }
  16. return cord[l].second;
  17. }
  18. void read(int x, int y, vector<pair<int, int>>& cord, int& left, int& right){
  19. cord.push_back({x, y});
  20. left=x;
  21. int a=x;
  22. int b=y;
  23. while(true){
  24. char p;
  25. cin>>p;
  26. if (p=='0'){
  27. right=a;
  28. break;
  29. }
  30. if (p=='+'){
  31. int q;
  32. cin>>q;
  33. b+=q;
  34. cord.push_back({a, b});
  35. }
  36. if (p=='-'){
  37. int q;
  38. cin>>q;
  39. a+=q;
  40. cord.push_back({a, b});
  41. }
  42. }
  43. }
  44. signed main(){
  45. int p;
  46. cin>>p;
  47. vector<pair<int, int>> cord1;
  48. vector<pair<int, int>> cord2;
  49. int x, y;
  50. cin>>x>>y;
  51. int left, right;
  52. pair<int, int> cur={x, y};
  53. vector<pair<int, int>> fish(p);
  54. for (int i=0; i<p; i++){
  55. cin>>fish[i].first>>fish[i].second;
  56. }
  57. read(x, y, cord1, left, right);
  58. read(x, y, cord2, left, right);
  59. int cnt=0;
  60. for (int i=0; i<p; i++){
  61. int stolb=fish[i].first;
  62. if (stolb<left || stolb>right){
  63. continue;
  64. }
  65. if (stolb==left){
  66. if(fish[i].second==y){
  67. cnt++;
  68. }
  69. continue;
  70. }
  71. if (stolb==right){
  72. if (fish[i].second==cord1[cord1.size()-1].second){
  73. cnt++;
  74. }
  75. continue;
  76. }
  77. int str1=str(cord1, stolb);
  78. int str2=str(cord2, stolb);
  79. if (min(str1, str2)<=fish[i].second && max(str1, str2)>=fish[i].second){
  80. cnt++;
  81. }
  82. }
  83. cout<<cnt<<"\n";
  84. return 0;
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement