Bzoj 2741 "Fotile simulation" L tiles + persistent trie tree

Source: Internet
Author: User

Main topic

A sequence is given to find the maximum continuous in [L, R] xor And.
Force Online

Ideas

First, divide the entire sequence into n   √ block, preprocessing the beginning of each block to the maximum continuous of each number xor And. We just have to deal with the prefix. xor And, after that, it can be done with a trie tree that can be persisted. So the right side of the question is the whole block. The rest of the left side of the casual violence can be over.

CODE
#define _crt_secure_no_warnings#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 15000using namespace STD;intCNT, asks;intSrc[max];intblocks, size;intBelong[max];intSt[max], Ed[max];structtrie{Trie *son[2];intCNT;} Mempool[max * -], *c = Mempool; Trie *trie[max], **tree = Trie +1; Trie *newtrie (Trie *_, Trie *__,int___) {c->son[0] = _; c->son[1] = __; c->cnt = ___;returnC + +;} Trie *insert (Trie *consult,intCintDeep) {if(!deep)returnNewtrie (null, NULL, CONSULT-&GT;CNT +1);if(! (~c&deep))returnNewtrie (consult->son[0], Insert (consult->son[1], C, deep >>1), consult->cnt +1);Else        returnNewtrie (Insert (consult->son[0], C, deep >>1), consult->son[1], consult->cnt +1);}intGetmax (Trie *l, Trie *r,intXintDeep) {if(!deep)return 0;BOOLdir = x&deep?0:1;if(r->son[dir]->cnt-l->son[dir]->cnt)returnDeep + getmax (L->son[dir], R->son[dir], X,deep >>1);Else        returnGetmax (L->son[!dir], R->son[!dir], x, deep >>1);}intans[ -][max];intMain () {Cin>> CNT >> asks; for(inti =1; I <= CNT; ++i) {scanf("%d", &src[i]); Src[i] ^= src[i-1]; } size =sqrt(CNT +1);memset(St,-1,sizeof(ST)); for(inti =0; I <= CNT; ++i) {Belong[i] = i/size;if(St[belong[i]] = =-1) St[belong[i]] = i;    Ed[belong[i]] = i;    } blocks = belong[cnt]; tree[-1] = Newtrie (c, C,0); tree[0] = Insert (tree[-1],0,1<< -); for(inti =1; I <= CNT; ++i) Tree[i] = Insert (Tree[i-1], Src[i],1<< -); for(inti =0; I <= blocks; ++i) for(intj = St[i]; J <= CNT; ++J) Ans[i][j] = max (Getmax (tree[st[i)-1], Tree[j], src[j],1<< -), J? Ans[i][j-1] :0);intLast_ans =0; for(intX, y, i =1; I <= asks; ++i) {scanf("%d%d", &x, &y); x = ((Long Long) x + Last_ans)% cnt +1; y = ((Long Long) y + Last_ans)% cnt +1;if(x > Y) Swap (x, y); --x;intt = belong[x] +1; Last_ans = Ans[t][y]; for(intj = min (St[t]-1, y); J >= X; --J) Last_ans = max (Last_ans, Getmax (Tree[x-1], Tree[y], src[j],1<< -));printf("%d\n", Last_ans); }return 0;}

Bzoj 2741 "Fotile simulation" L tiles + persistent trie tree

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.