题意:对于一个16进制数x,把x的各个数位拿出来,设其为t1,t2,...,定义s(x)为2^t1|2^t2|...,如x=0x3e53,则s(x)=2^3|2^14|2^5|2^3=16424.给出q组询问l,r(l,r也是16进制数,不超过15位),求[l,r]中有多少个数x满足x^s(x) 这题题解写的是个状压数位dp,但是蒟蒻不会数位dp,自己YY了一个做法. 首先,将[l,r]的询问拆成2个前缀和,考虑到十六进制数减1并不方便,可以转化为solve(r)-solve(l),再特判一下l满不满足要求. 考虑求出[0,upper]间的答案.将二进制位从低位向高位,从0开始编号.观察x和s(x)的二进制表示,可以发现当且仅当s(x)的最高位1所在的数位上x也为1时,x^s(x) 1 program cf776G;
2 const number=['a'..'f','0'..'9'];
3 list:array[0..15]of char=('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
4 var q,i:longint;
5 l,r:string;
6 num:array[char] of longint;
7 ch:char;
8 procedure getstr(var s:string);
9 var ch:char;
10 begin
11 s:='';
12 read(ch);
13 while not (ch in number) do read(ch);
14 while ch in number do
15 begin
16 s:=s+ch;
17 read(ch);
18 end;
19 end;
20 function check(const x:string):longint;
21 var i:longint;
22 t,this:int64;
23 begin
24 this:=0;
25 for i:=1 to length(x) do this:=this*16+num[x[i]];
26 t:=0;
27 for i:=1 to length(x) do t:=t or (1 shl num[x[i]]);
28 exit(ord(this xor t<this));
29 end;
30 function solve2(const upper:string;id,up:longint):int64;
31 var upp,ans:int64;
32 i,this,t:longint;
33 sw:array[0..30] of longint;
34 pow:array[0..20] of int64;
35 begin
36 upp:=0;
37 for i:=1 to length(upper) do upp:=upp*16+num[upper[i]];
38 for i:=1 to length(upper) do sw[length(upper)-i]:=num[upper[i]];
39 if(1 shl (id mod 4)>up)or(1 shl id>upp)or(up<0) then exit(0);
40 t:=0;
41 for this:=0 to up do if this and (1 shl (id mod 4))>0 then inc(t);
42 ans:=0;
43 pow[0]:=1;
44 for i:=1 to length(upper) do pow[i]:=pow[i-1]*(up+1);
45 for i:=length(upper)-1 downto 0 do
46 if i=id div 4 then
47 begin
48 if up