Advertisement
ekzolot

Untitled

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