#P13293. [GCJ 2013 #1C] The Great Wall

    ID: 15158 远端评测题 6000~30000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2013线段树离散化Google Code Jam

[GCJ 2013 #1C] The Great Wall

题目描述

You are studying the history of the Great Wall of China, which was built by the Chinese to protect against military incursions from the North. For the purposes of this problem, the Great Wall stretches from infinity in the East to minus infinity in the West. As this is a lot of distance to cover, the Great Wall was not built at once. Instead, for this problem we assume that the builder used a reactive strategy: whenever a part of the border was attacked successfully, the Wall on this part of the border would be raised to the height sufficient to stop an identical attack in the future.

The north border of China was frequently attacked by nomadic tribes. For the purposes of this problem, we assume that each tribe attacks the border on some interval with some strength SS. In order to repel the attack, the Wall must have height SS all along the defended interval. If even a short stretch of the Wall is lower than needed, the attack will breach the Wall at this point and succeed. Note that even a successful attack does not damage the Wall. After the attack, every attacked fragment of the Wall that was lower than SS is raised to height SS — in other words, the Wall is increased in the minimal way that would have stopped the attack. Note that if two or more attacks happened on the exact same day, the Wall was raised only after they all resolved, and is raised in the minimum way that would stop all of them.

Since nomadic tribes are nomadic, they did not necessarily restrict themselves to a single attack. Instead, they tended to move (either to the East or to the West), and periodically attack the Wall. To simplify the problem, we assume they moved with constant speed and attacked the Wall at constant intervals; moreover we assume that the strength with which a given tribe attacked the Wall changed by a constant amount after each attack (either decreased from attrition, or grew from experience).

Assuming that initially (in 250 BC) the Wall was nonexistent (i.e., of height zero everywhere), and given the full description of all the nomadic tribes that attacked the Wall, determine how many of the attacks were successful.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing a single integer NN: the number of the tribes attacking the Wall. NN lines follow, each describing one tribe. The iith line contains eight integers did_i, nin_i, wiw_i, eie_i, sis_i, delta_di\text{delta\_d}_i, delta_pi\text{delta\_p}_i and delta_si\text{delta\_s}_i separated by spaces, describing a single nomadic tribe:

  • did_i – the day of the tribe's first attack (where 1st January, 250BC, is considered day 0)
  • nin_i – the number of attacks from this tribe
  • wiw_i, eie_i – the westmost and eastmost points respectively of the Wall attacked on the first attack
  • sis_i – the strength of the first attack
  • delta_di\text{delta\_d}_i – the number of days between subsequent attacks by this tribe
  • delta_pi\text{delta\_p}_i – the distance this tribe travels to the east between subsequent attacks (if this is negative, the tribe travels to the west)
  • delta_si\text{delta\_s}_i – the change in strength between subsequent attacks

输出格式

For each test case, output one line containing "Case #x: y", where xx is the case number (starting from 1) and yy is the number of attacks that succeed.

2
2
0 3 0 2 10 2 3 -2
10 3 2 3 8 7 2 0
3
1 2 0 5 10 2 8 0
0 3 0 1 7 1 2 2
3 3 0 5 1 1 4 0
Case #1: 5
Case #2: 6

提示

Sample Explanation

In the first case, the first tribe attacks three times: on day 00 it hits the interval [0,2][0,2] at height 1010, on day 22 it hits [3,5][3,5] at height 88 and on day 44 it hits [6,8][6,8] at height 66; all three attacks succeed. Then the second tribe attacks three times, each time at height 88 - on day 1010 it hits [2,3][2,3] (this succeeds, for example at position 2.52.5, where the Wall has still height 00), on day 1717 it hits [4,5][4,5] (this fails, the Wall is already of height 88 in the interval [3,5][3, 5], which covers [4,5][4, 5]), and on day 2424 it hits [6,7][6,7] (this succeeds, as the Wall there was of height 66).

In the second case there are three tribes, and their attacks intermingle. The sequence is as follows:

  • On day 00, Tribe 22 attacks [0,1][0,1] at height 77 and succeeds.
  • On day 11, Tribe 11 attacks [0,5][0,5] at height 1010, and Tribe 22 attacks [2,3][2,3] at height 99. Both attacks succeed (as they were simultaneous, the Wall built after the attack of the first tribe isn't there in time to stop the second tribe).
  • On day 22, Tribe 22 attacks [4,5][4,5] at height 1111 and succeeds (the Wall there was at height 1010).
  • On day 33, Tribe 11 attacks [8,13][8,13] at height 1010 and succeeds. Simultaneously, Tribe 33 attacks [0,5][0,5] at height 11 and fails (there's a Wall of heights 1010 and 1111 there).
  • On day 44 Tribe 33 attacks [4,9][4,9] at height 11 and succeeds (there was no Wall between 55 and 88).
  • Finally, on day 55 Tribe 33 attacks [8,13][8,13] at height 11 and fails (since a Wall of height 1010 is there).

Limits

  • 1T201 \leq T \leq 20.
  • 0di0 \leq d_i.
  • 1delta_di6760601 \leq \text{delta\_d}_i \leq 676060.
  • $d_i + (n_i - 1) \times \text{delta\_d}_i \leq 676060$.
  • 1si1061 \leq s_i \leq 10^6.
  • 105delta_si105-10^5 \leq \text{delta\_s}_i \leq 10^5.
  • si+(ni1)×delta_si1s_i + (n_i - 1) \times \text{delta\_s}_i \geq 1.

Small dataset (9 Pts, Test set 1 - Visible)

  • 1N101 \leq N \leq 10.
  • 1ni101 \leq n_i \leq 10.
  • 100wi<ei100-100 \leq w_i < e_i \leq 100.
  • 10delta_pi10-10 \leq \text{delta\_p}_i \leq 10.

Large dataset (28 Pts, Test set 2 - Hidden)

  • 1N10001 \leq N \leq 1000.
  • 1ni10001 \leq n_i \leq 1000.
  • 106wi<ei106-10^6 \leq w_i < e_i \leq 10^6.
  • 105delta_pi105-10^5 \leq \text{delta\_p}_i \leq 10^5.