hccz95

 

[Ioi2005]mou

View Code
1 Source
2
3 Problem Id:1809 User Id:hccz95
4 Memory:81896K Time:2791MS
5 Language:Pascal Result:Accepted
6
7 Source
8
9  var tree : array[ 0..5000000 ] of record Ls , Rs , k , sum , max : Longint end;
10 n , tot : Longint ;
11
12 function maxi( a , b : Longint ) : Longint ;
13 begin
14 if a > b then exit( a ) else exit( b );
15 end;
16
17 procedure add;
18 begin
19 inc( tot );
20 with tree[ tot ] do
21 begin
22 k := 0 ;
23 Ls := -1 ; Rs := -1 ;
24 end;
25 end;
26
27 procedure insert( v , L , R , a , b , c : Longint );
28 var m : Longint ;
29 begin
30 if ( L = a ) and ( R = b ) then
31 begin
32 tree[ v ].k := c ;
33 tree[ v ].sum := ( R - L + 1 ) * tree[ v ].k ;
34 tree[ v ].max := tree[ v ].sum ;
35 exit;
36 end;
37 m := ( L + R ) >> 1 ;
38 if tree[ v ].k <> maxlongint then
39 with tree[ v ] do
40 begin
41 if Ls = -1 then
42 begin
43 add; Ls := tot ;
44 end;
45 if Rs = -1 then
46 begin
47 add; Rs := tot ;
48 end;
49 tree[ Ls ].k := k ;
50 tree[ Ls ].sum := ( m - L + 1 ) * k ;
51 tree[ Ls ].max := maxi( tree[ Ls ].sum , 0 );
52 tree[ Rs ].k := k ;
53 tree[ Rs ].sum := ( R - m ) * k ;
54 tree[ Rs ].max := maxi( tree[ Rs ].sum , 0 );
55 k := maxlongint;
56 end;
57 with tree[ v ] do
58 begin
59 if b <= m then
60 begin
61 if Ls = -1 then
62 begin
63 add; Ls := tot ;
64 end;
65 insert( Ls , L , m , a , b , c );
66 end else
67 if a > m then
68 begin
69 if Rs = -1 then
70 begin
71 add; Rs := tot ;
72 end;
73 insert( Rs , m+1 , R , a , b , c );
74 end else
75 begin
76 insert( Ls , L , m , a , m , c );
77 insert( Rs , m+1 , R , m+1 , b , c );
78 end;
79 sum := tree[ Ls ].sum + tree[ Rs ].sum ;
80 max := maxi( tree[ Ls ].max , tree[ Ls ].sum + tree[ Rs ].max );
81 end;
82 end;
83
84 function count( v , L , R , h : Longint ) : Longint ;
85 var m , tmp : Longint ;
86 begin
87 if tree[ v ].k <> maxlongint then
88 begin
89 if tree[ v ].k > 0 then
90 begin
91 tmp := L + h div tree[ v ].k ;
92 if tmp > R + 1 then tmp := R + 1 ;
93 end else
94 tmp := R + 1 ;
95 exit( tmp );
96 end;
97 m := ( L + R ) >> 1 ;
98 with tree[ v ] do
99 if h >= tree[ Ls ].max then
100 exit( count( Rs , m+1 , R , h - tree[ Ls ].sum ) ) else
101 exit( count( Ls , L , m , h ) );
102 end;
103
104 procedure main;
105 var a , b , c : Longint ;
106 ch : Char ;
107 begin
108 readln( n );
109 add;
110 while true do
111 begin
112 read( ch );
113 if ch = 'E' then exit;
114 if ch = 'Q' then
115 begin
116 readln( c );
117 writeln( count( 1 , 1 , n , c ) - 1 );
118 end else
119 begin
120 readln( a , b , c );
121 insert( 1 , 1 , n , a , b , c );
122 end;
123 end;
124 end;
125
126 begin
127 main;
128 end.

[Ioi2005]mou

Time Limit:10000MS  Memory Limit:165536K
Total Submit:18 Accepted:9
Case Time Limit:1000MS

Description

游乐园已经开始运行一个崭新的模拟过山车。模拟的轨道由n 段铁轨组成,并且首尾相连。第一段铁轨从高度0开始。操作员Byteman能通过调整连续几段的铁轨高度来改造这条轨道。在被改造的一段前面的铁轨高度不受影响。 每一次铁轨被调整。后面的轨必须升起或降低来保持连通,并保证起点高度为0。下页举例说明轨道改造过程。
每次开始时车都有足够能量到达高度h。也就是说,只要轨道的高度不超过 h车就一直开下去, 甚至直到结束。
给出每天的运行和改造情况, 为每次运行计算在车停止前,到达的铁轨数。铁轨以一个n个数的数列形式表示 ,一个数对应一段铁轨。第i个di表示在第i段铁轨上的高度变化。也就是说,在到达铁轨i前,如果车的高度是h,那么经过铁轨i后,高度变为h+di。最初轨道是一条水平线。就是说对于所有的i都是di=0。运行和改造交错进行。 每个改造用三个数表示: a , b 和 D。表示从a到b(包括a,b)的所有di改为di=D。每次运行给定一个数字h ——车能到达的最大高度。

Input

输入的第一行包括一个正整数n——铁轨的数目,1≤n≤1000000000。下面的行包括改造和运行,各有一个标识符:
*改造——一个字母I,和整数a,b,D(1≤a≤b≤n,-1000000000≤D≤1000000000),中间用一个空格隔开。
*运行——一个字母Q,和一个整数h(0≤h≤1000000000),用一个空格隔开。
*一个字母E——结束符号,表示输入结束。
你可以假设任意时刻任意铁轨的高度在[1,1000000000]区间内。输入不超过10000行。
50%的数据n满足1≤n≤20000且输入不超过1000行。

Output

第i行需包含一个整数,
即第i次运行经过的铁轨数。

Sample Input

4
Q 1
I 1 4 2
Q 3
Q 1
I 2 2 -1
Q 3
E

Sample Output

4
1
0
3


posted on 2011-03-20 11:35  hccz95  阅读(223)  评论(0)    收藏  举报

导航