Color the ball interval

N balloons are arranged in a row, numbered from left to right as 1, 2, 3.... The "Flying Pigeon" brand electric car paints each balloon in turn from balloon a to balloon b. But after N times, Lele has forgotten how many times the first balloon has been painted. Can you help him figure out how many times each balloon has been painted?

Input The first line of each test instance is an integer N, (N <= 100000). The next N lines, each line includes 2 integers ab (1 <= a <= b <= N).
When N = 0, the input ends. Output Output a line for each test instance, including N integers, the 1th number represents the total number of times the ith balloon is painted. Sample Input
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
Sample Output
1 1 1
3 2 1


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
#define ll long long
int main(){
    int n;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.txt","r",stdin);
    //cout<<"1"<<endl;
    while(cin>>n,n){
        //cout<<n<<endl;
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++){
            int x,y;
            cin>>x>>y;
            a[x]++;
            a[y+1]--;
        }
        ll ans=0;
        for(int i=1;i<=n;i++){
            ans+=a[i];
            if(i==1)
            cost<<years;
            else cout<<" "<<ans;
        }
        cout<<endl;
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324787197&siteId=291194637