Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long long n, q, d, ans = 0, x;
- vector < long long > pos, type;
- vector < int > mark, vis;
- void affect(int x){
- //cout << x << endl;
- mark[x-1] = 1;
- if(vis[x-1]==1) return;
- vis[x-1] = 1;
- if(type[x-1] == 0){
- for(int j=x;j<n;j++){
- if(pos[j]-pos[x-1] > d) break;
- else affect(j+1);
- }
- for(int j=x-2;j>=0;j--){
- if(pos[x-1]-pos[j] > d) break;
- else affect(j+1);
- }
- }
- else {
- for(int j=x;j<n;j++){
- if(pos[j]-pos[x-1] > 2*d) break;
- else affect(j+1);
- }
- for(int j=x-2;j>=0;j--){
- if(pos[x-1]-pos[j] > 2*d) break;
- else affect(j+1);
- }
- }
- return;
- }
- int main()
- {
- cin >> n;
- mark.assign(n,0);
- vis.assign(n,0);
- pos.assign(n,0);
- type.assign(n,0);
- for(int i=0;i<n;i++) cin >> pos[i];
- for(int i=0;i<n;i++) cin >> type[i];
- cin >> q >> d;
- for(int i=0;i<q;i++) {
- cin >> x;
- affect(x);
- }
- // for(auto num : mark) cout << num << endl;
- for(auto num : mark) if(num == 1) ans++;
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment