• BZOJ3261 最大异或和 (可持久化Trie)


    const maxn=600008;
          len=24;
    var x,y,z,n,m,tot,lx,i:longint;
        sum:array[0..maxn] of longint;
        rt:array[0..maxn] of longint;
        time,l,r:array[0..maxn*len] of longint;
        ch:char;
    procedure insert(x:longint);inline;
    var p,i:longint;
    begin
        rt[lx]:=tot+1; p:=rt[lx-1];
        for i:=len downto 1 do
        begin
            inc(tot); l[tot]:=l[p]; r[tot]:=r[p]; time[tot]:=time[p]+1;
            if (x and (1<<(i-1))) >0 then
            begin
                p:=r[p];
                r[tot]:=tot+1;
            end else
            begin
                p:=l[p];
                l[tot]:=tot+1;
            end;
        end;
        inc(tot); l[tot]:=l[p]; r[tot]:=r[p]; time[tot]:=time[p]+1;
    end;
    function query(a,b,x:longint):longint;inline;
    var ans,i:longint;
    begin
        ans:=0;
        for i:=len downto 1 do
        begin
            if (x and (1<<(i-1))) >0 then
            begin
                if time[l[b]]>time[l[a]] then
                begin
                    a:=l[a]; b:=l[b];
                    ans:=ans+1<<(i-1);
                end
                else
                begin
                    a:=r[a]; b:=r[b];
                end
            end else
            begin
                if time[r[b]]>time[r[a]] then
                begin
                    a:=r[a]; b:=r[b];
                    ans:=ans+1<<(i-1);
                end
                else
                begin
                    a:=l[a]; b:=l[b];
                end
            end;
        end;
        exit(ans);
    end;
    begin
        readln(n,m);
        sum[0]:=0; lx:=1;
        insert(0);
        for i:=1 to n do
        begin
                    read(x);
            inc(lx);
            sum[lx]:=x xor sum[lx-1];
            insert(sum[lx]);
        end;
        readln;
        for i:=1 to m do
        begin
            read(ch);
            if ch='A' then
            begin
                readln(x);
                inc(lx);
                sum[lx]:=x xor sum[lx-1];
                insert(sum[lx]);
            end else
            begin
                readln(x,y,z);
                writeln(query(rt[x-1],rt[y],z xor sum[lx]));
            end;
        end;
    end.
            
  • 相关阅读:
    大道至简第一章和java理论学时第一节。感受。
    jQuery基础
    JavaScript对象及初始面向对象
    使用JavaScript操作DOM
    JavaScript操作BOM对象
    JavaScript基础
    实体之间的对应关系
    MySQL常用函数
    SQL Server中分离附加数据及生成SQL脚本
    C#中子类构造函数
  • 原文地址:https://www.cnblogs.com/rpSebastian/p/4354111.html
Copyright © 2020-2023  润新知