社区讨论
存程序
P2787语文1(chin1)- 理理思维参与者 5已保存回复 7
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 7 条
- 当前快照
- 1 份
- 快照标识符
- @mi4eed8j
- 此快照首次捕获于
- 2025/11/18 17:55 4 个月前
- 此快照最后确认于
- 2025/11/18 17:55 4 个月前
CPP
program aaa;
type point=record
c:array[1..26] of longint;
cover:longint;
end;
var n,m,i,k,x,y,o,tmp:longint;
pos1:char;
s:array[0..50000] of char;
t:array[0..200000] of point;
procedure build(p,l,r:longint);
var m,j:longint;
begin
t[p].cover:=0;
if l=r then
begin
t[p].c[ord(s[l])-64]:=1;
exit;
end;
m:=(l+r) shr 1;
build(p*2,l,m);
build(P*2+1,m+1,r);
for j:=1 to 26 do t[p].c[j]:=t[p*2].c[j]+t[p*2+1].c[j];
end;
procedure change(p,l,r:longint;var px,py,po:longint);
var mid:longint;
begin
if t[p].cover<>0 then
begin
fillchar(t[p].c,sizeof(t[p].c),0);
t[p].c[t[p].cover]:=r-l+1;
t[2*p].cover:=t[p].cover;
t[2*p+1].cover:=t[p].cover;
end;
if (l>=px) and (r<=py) then
begin
t[p].cover:=po;
exit;
end;
mid:=(l+r) shr 1;
if px<=mid then change(p*2,l,mid,px,py,po);
if py>mid then change(p*2+1,mid+1,r,px,py,po);
end;
function answer(p,l,r:longint;var px,py,po:longint):longint;
var mid,xs:longint;
begin
if t[p].cover<>0 then
begin
fillchar(t[p].c,sizeof(t[p].c),0);
t[p].c[t[p].cover]:=r-l+1;
t[2*p].cover:=t[p].cover;
t[2*p+1].cover:=t[p].cover;
end;
if (l=px) and (r=py) then exit(t[p].c[po]);
mid:=(l+r) shr 1;
if py<=mid then exit(answer(p*2,l,mid,px,py,po));
if px>mid then exit(answer(P*2+1,mid+1,r,px,py,po));
xs:=mid+1;
if (px<=mid) and (py>mid) then exit(answer(p*2,l,mid,px,mid,po)+answer(P*2+1,mid+1,r,xs,py,po));
end;
procedure sort(p,l,r:longint;var px,py:longint);
begin
end;
begin
readln(n,m);
for i:=1 to n do
begin
read(s[i]);
if (s[i]<='z') and (s[i]>='a') then s[i]:=chr(ord(s[i])-32);
end;
build(1,1,n);
for i:=1 to m do
begin
read(o);
if o=1 then
begin
read(x,y,pos1);
while pos1=' ' do read(pos1);
readln;
tmp:=ord(pos1)-64;
writeln(pos1);
writeln(answer(1,1,n,x,y,tmp));
end;
if o=2 then
begin
read(x,y,pos1);
while pos1=' ' do read(pos1);
readln;
tmp:=ord(pos1)-64;
change(1,1,n,x,y,tmp);
end;
if o=3 then
begin
readln(x,y);
sort(1,1,n,x,y);
end;
end;
end.
回复
共 7 条回复,欢迎继续交流。
正在加载回复...