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