#include <bits/stdc++.h>
#include "infection.h"

using namespace std;

bool inf[150001];
vector<int>ans;
vector<int>v[150000];
int ans1[150000];

vector<int> solve(vector<pair<int, int>> R, vector<long long> D, vector<int> S, vector<int> T, vector<bool> I)
{
    memset(inf, false, sizeof(inf));
    int n=R.size()+1;
    int m=D.size();
    for(int i=0; i<m; i++)
    {
        int st=S[i];
        v[st].push_back(i);
        if(I[i])inf[st]=true;
    }
    for(int i=0; i<n; i++)
    {
        if(v[i].size()==0)continue;
        for(int j=0; j<v[i].size(); j++)
        {
            int bro=v[i][j];
            if(inf[i])
            {
                ans1[bro]=abs(T[bro]-S[bro])+1;
            }
            else ans1[bro]=0;
        }
    }
    for(int i=0; i<m; i++)
    {
        ans.push_back(ans1[i]);
        //cout<<ans[i]<<endl;
    }
    return ans;
}
