eolymp
bolt
Try our new interface for solving problems
Məsələlər

Can of Worms

Can of Worms

There is an old adage about opening a can of worms. A lesser known adage is one about shooting a can of exploding worms with a BB gun. Imagine we place some cans of exploding worms on a long, straight fence. When a can is shot, all of the worms inside will explode. Different types of worms have different blast radii. Each can contains only one kind of worm. When a can explodes, if another can is in the blast radius, then that can will also explode, possibly creating a chain reaction. Each can explodes only once. This process continues until all explosions stop. For each can, suppose that it is the only can shot. How many cans in total will explode? \InputFile There will be several test cases in the input. Each test case will begin with a line with a single integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}) representing the number of cans on that fence. Each of the next \textbf{n} lines will have two integers \textbf{x} (\textbf{-10^9} ≤ \textbf{x} ≤ \textbf{10^9}) and \textbf{r} (\textbf{1} ≤ \textbf{r} ≤ \textbf{10^9}), where \textbf{x} is the location of the can on the fence and \textbf{r} is the blast radius. No two cans will occupy the same location. The input will end with a line with a single \textbf{0}. \OutputFile For each fence, print \textbf{n} integers on a single line separated by single spaces. The \textbf{i}^th integer represents the number of cans that will explode if the ith can is the one that is shot. Output no extra spaces, and do not print any blank lines between outputs.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Mənbə The University of Chicago Invitational Programming Contest 2013, March 29-31, 2013