Advertisement
ekzolot

Untitled

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