记录编号 |
227230 |
评测结果 |
AATTAAATTTT |
题目名称 |
快速红包变换 |
最终得分 |
45 |
用户昵称 |
这_不错 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
6.283 s |
提交时间 |
2016-02-18 15:46:55 |
内存使用 |
190.90 MiB |
显示代码纯文本
program fy;
var n,m,i,j:longint;ch:char;
s:ansistring;
red_packet:array[1..50000000]of longint;
function mina(x,y:longint):longint;
begin
if x>y then mina:=y
else mina:=x;
end;
function maxa(x,y:longint):longint;
begin
if y>x then maxa:=y
else maxa:=x;
end;
procedure readlnred_packet;
begin
readln(n);
for i:=1 to n-1 do
read(red_packet[i]);
readln(red_packet[n]);
end;
procedure Cadd(l,r,a:longint);
begin
for i:=l to r do
red_packet[i]:=red_packet[i]+a;
end;
procedure Cchange(l,r,a:longint);
begin
for i:=l to r do
red_packet[i]:=a;
end;
procedure Cbmax(l,r,a:longint);
begin
for i:=l to r do
red_packet[i]:=maxa(red_packet[i],a);
end;
procedure Cbmin(l,r,a:longint);
begin
for i:=l to r do
red_packet[i]:=mina(red_packet[i],a);
end;
procedure Qsum(l,r:longint);
var sum:longint;
begin
sum:=0;
for i:=l to r do
sum:=sum+red_packet[i];
writeln(sum);
end;
procedure Qmax(l,r:longint);
var max,fin:longint;
begin
fin:=0;
max:=red_packet[l];
for i:=l+1 to r do
if red_packet[i]>max then max:=red_packet[i];
if s[2]='w'then writeln(max) else
begin
for i:=l to r do
if red_packet[i]=max then fin:=fin+1;
writeln(fin);
end;
end;
procedure Qmin(l,r:longint);
var min,fin:longint;
begin
fin:=0;
min:=red_packet[l];
for i:=l to r do
if red_packet[i]<min then min:=red_packet[i];
if s[2]='w' then writeln(min) else
begin
for i:=l to r do
if red_packet[i]=min then fin:=fin+1;
writeln(fin);
end;
end;
procedure just_do_it;
var l,r,a:longint;
begin
readln(m);
for j:=1 to m do
begin
read(ch);s:='';
while ch<>' ' do
begin
s:=s+ch;
read(ch);
end;
if s='Cadd' then
begin
readln(l,r,a);
Cadd(l,r,a);
end
else if s='Cchange' then
begin
readln(l,r,a);
Cchange(l,r,a);
end
else if s='Cbmax' then
begin
readln(l,r,a);
Cbmax(l,r,a);
end
else if s='Cbmin' then
begin
readln(l,r,a);
Cbmin(l,r,a);
end
else if s='Qsum' then
begin
readln(l,r);
Qsum(l,r);
end
else if s[1]='Q' then
begin
readln(l,r);
if s[4]='a' then Qmax(l,r)
else Qmin(l,r);
end;
end;
end;
begin
assign(input,'redbag.in');reset(input);
assign(output,'redbag.out');rewrite(output);
readlnred_packet;
just_do_it;
close(input);
close(output);
end.