Promi_38

Covid 19 By Mehraj

Jan 9th, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long n, q, d, ans = 0, x;
  6. vector < long long > pos, type;
  7. vector < int > mark, vis;
  8.  
  9.  
  10. void affect(int x){
  11.     //cout << x << endl;
  12.     mark[x-1] = 1;
  13.     if(vis[x-1]==1) return;
  14.     vis[x-1] = 1;
  15.         if(type[x-1] == 0){
  16.             for(int j=x;j<n;j++){
  17.                 if(pos[j]-pos[x-1] > d) break;
  18.                 else affect(j+1);
  19.             }
  20.             for(int j=x-2;j>=0;j--){
  21.                 if(pos[x-1]-pos[j] > d) break;
  22.                 else affect(j+1);
  23.             }
  24.         }
  25.         else {
  26.             for(int j=x;j<n;j++){
  27.                 if(pos[j]-pos[x-1] > 2*d) break;
  28.                 else affect(j+1);
  29.             }
  30.             for(int j=x-2;j>=0;j--){
  31.                 if(pos[x-1]-pos[j] > 2*d) break;
  32.                 else affect(j+1);
  33.             }
  34.         }
  35.         return;
  36. }
  37.  
  38. int main()
  39. {  
  40.     cin >> n;
  41.  
  42.     mark.assign(n,0);
  43.     vis.assign(n,0);
  44.     pos.assign(n,0);
  45.     type.assign(n,0);
  46.  
  47.     for(int i=0;i<n;i++) cin >> pos[i];
  48.     for(int i=0;i<n;i++) cin >> type[i];
  49.        
  50.        cin >> q >> d;
  51.  
  52.     for(int i=0;i<q;i++) {
  53.         cin >> x;
  54.         affect(x);
  55.     }
  56.  
  57.     // for(auto num : mark) cout << num << endl;
  58.  
  59.     for(auto num : mark) if(num == 1) ans++;
  60.    
  61.  
  62.     cout << ans << endl;
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment