Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int str(vector<pair<int, int>>& cord, int stolb){
- int n=(int) cord.size();
- if (stolb<cord[0].first || stolb>cord[n-1].first){
- return -1;
- }
- int l=-1;
- int r=n;
- while(r-l>1){
- int m=(l+r)/2;
- if (cord[m].first<=stolb){
- l=m;
- }else{
- r=m;
- }
- }
- return cord[l].second;
- }
- int main(){
- int p;
- cin>>p;
- vector<pair<int, int>> cord1;
- vector<pair<int, int>> cord2;
- int x, y;
- cin>>x>>y;
- cord1.push_back({x, y});
- cord2.push_back({x, y});
- pair<int, int> cur={x, y};
- vector<pair<int, int>> fish(p);
- for (int i=0; i<p; i++){
- cin>>fish[i].first>>fish[i].second;
- }
- while(true){
- char p;
- cin>>p;
- if (p=='+'){
- int q;
- cin>>q;
- cur.second+=q;
- cord1.push_back(cur);
- }
- if (p=='-'){
- int q;
- cin>>q;
- cur.first+=q;
- cord1.push_back(cur);
- }
- if (p=='0'){
- break;
- }
- }
- cur={x, y};
- while(true){
- char p;
- cin>>p;
- if (p=='+'){
- int q;
- cin>>q;
- cur.second+=q;
- cord2.push_back(cur);
- }
- if (p=='-'){
- int q;
- cin>>q;
- cur.first+=q;
- cord2.push_back(cur);
- }
- if (p=='0'){
- break;
- }
- }
- int cnt=0;
- for (int i=0; i<p; i++){
- int stolb=fish[i].first;
- int str1=str(cord1, stolb);
- int str2=str(cord2, stolb);
- if (str1==-1 || str2==-1){
- continue;
- }
- if (min(str1, str2)<=fish[i].second && max(str1, str2)>=fish[i].second){
- cnt++;
- }
- }
- cout<<cnt<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement