Advertisement
ekzolot

Untitled

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