#include <bits/stdc++.h>

using namespace std;

vector<int> solve(vector<pair<int, int>>r,vector<long long>d,vector<int>s,vector<int>t,vector<bool>I)
{
    int m = s.size();
    vector<pair<int, int>>ord;
    for(int i = 0; i<m;i++)
    {
        ord.push_back({s[i], i});
    }
    sort(ord.begin(), ord.end());
    vector<int>begs = {0};
    vector<int> p = {I[ord[0].second]};
    for(int i = 0; i<n-1;i++)
    {
        p.push_back(p[p.size()-1]+I[ord[i+1].second]);
        if(ord[i].first!=ord[i+1].first)
        {
            begs.push_back(i+1);
        }
    }
    begs.push_back(n);
    vector<int>res;
    for(int i = 0; i<n;i++)
    {
        res.push_back(0);
    }
    for(int i = 0 ; i<begs.size()-1;i++)
    {
        int a, b;
        a = begs[i];
        b = [begs[i+1]-1];
        int some = p[b] - p[a] + I[ord[a].second];
        if(some >= 1)
        {
            for(int j = a; j<=b; j++)
            {
                int ind = ord[j].second;
                res[ind] = j[ind] - s[ind] + 1;
            }
        }
    }
    return res;
}
