"More than 2016 schools" T3 subset (sub-block, pressure DP)

Source: Internet
Author: User

3 subset

3.1 topics

at first you have an empty set, the collection can appear repeating elements, and then there are Q Operations

    1. Add s

adds the number s to the collection .

    1. del s

removes the number s from the collection . Guaranteed s presence

    1. CNT s

query satisfies a&s = number of a for a condition

3.2 Input

first line an integer Q Next , each row is one of 3 operations

3.3 Output

output answers for each CNT operation

3.4 Sample Input

7

Add one CNT add 4 Add 0 CNT 6 del 4 CNT 15

3.5 Sample Output

1

2

2

3.6 data set

Data for 30% :1 n 1000

for 100% data satisfaction,1 n 200000, 0 < s < 216

Ideas:

chunked calculation. A[pre][suf], where Pre < 28,suf <, indicates that the front 8 bits are pre, and the back 8 bits are suf

The number of the number of subsets.

then for each add and del operation, you can update The A array by up to a time enumeration Suf . For CNT operations, up to the pre-enumeration, the answer can be calculated time complexity O(n 28)

1 varDp:Array[0.. -,0.. -] ofLongint;2 S1,s2,n,i,x,j:longint;3 ch:string;4 5 procedureDFS1 (vars1,s2:longint;k,s:longint);6 begin7  ifK>7  Then8  begin9 Inc (Dp[s1,s]);Ten exit; One  End; A  ifS2 and(1&LT;&LT;K) >0  ThenDFS1 (s1,s2,k+1, S+ (1<<k)) -   Else -   begin theDFS1 (s1,s2,k+1, s); -DFS1 (s1,s2,k+1, S+ (1<<k)); -   End; - End; +  - procedureDFS2 (vars1,s2:longint;k,s:longint); + begin A  ifK>7  Then at  begin - Dec (dp[s1,s]); - exit; -  End; -  ifS2 and(1&LT;&LT;K) >0  ThenDFS2 (s1,s2,k+1, S+ (1<<k)) -   Else in   begin -DFS2 (s1,s2,k+1, s); toDFS2 (s1,s2,k+1, S+ (1<<k)); +   End; - End; the  * procedureAdd (x:longint); $ varI:longint;Panax Notoginseng begin -s1:=0; s2:=0; the   fori:= the Downto 8  Do +   ifX and(1<<i) >0  Thens1:=s1+1<< (I-8); A    fori:=7 Downto 0  Do the    ifX and(1<<i) >0  Thens2:=s2+1<<i; +DFS1 (S1,S2,0,0); - End; $  $ proceduredel (x:longint); - varI:longint; - begin thes1:=0; s2:=0; -   fori:= the Downto 8  DoWuyi   ifX and(1<<i) >0  Thens1:=s1+1<< (I-8); the    fori:=7 Downto 0  Do -    ifX and(1<<i) >0  Thens2:=s2+1<<i; WuDFS2 (S1,S2,0,0); - End; About  $ functionCNT (x:longint): Longint; - varRet,i,s:longint; - begin -ret:=0; As1:=0; s2:=0; +   fori:= the Downto 8  Do the   ifX and(1<<i) >0  Thens1:=s1+1<< (I-8); -   fori:=7 Downto 0  Do $   ifX and(1<<i) >0  Thens2:=s2+1<<i; thes:=S1; the   whileS>0  Do the  begin theret:=ret+DP[S,S2]; -S:=s1 and(S-1); in  End; theret:=ret+dp[0, S2]; the exit (ret); About End; the  the begin theAssign (input,'subset.in'); Reset (input); +Assign (output,'Subset.out'); Rewrite (output); - READLN (n); the   fori:=1  toN DoBayi  begin the READLN (CH); thex:=0; -    forj:=5  toLength (CH) Dox:=x*Ten+ord (Ch[j])-ord ('0'); -   ifch[1]='a'  ThenAdd (x); the   ifch[1]='D'  Thendel (x); the   ifch[1]='C'  ThenWriteln (CNT (x)); the  End; the close (input); - close (output); the End.

"More than 2016 schools" T3 subset (sub-block, pressure DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.