$dp$,字典树。

$dp$递推式很容易知道。dp[i]=max{dp[j]+1} a[j]^..^a[i]<=X,并且$[j,i]$长度不能超过$L$。

但是暴力来复杂度极高,所以需要用字典树维护这个东西。将前缀异或和插入到字典树中,然后不断维护$a[i]$位置之前$L$个前缀异或和就好了。

跑了$405ms$,第一次排到第一,有点激动~~~

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const LL mod=(LL);
const int maxn=;
LL a[maxn],X,P,Q;
int T,n,L,dp[maxn],h;
struct Node { int cnt,mx,nx[]; }s[*maxn];
int sz; bool fail,f[maxn]; int add()
{
s[sz].mx=; s[sz].cnt=;
s[sz].nx[]=s[sz].nx[]=-; sz++;
return sz-;
} void Delete(LL num)
{
int p=;
for(int i=;i>=;i--)
{
int x; LL g=(LL)(<<i); if(num&g) x=; else x=;
int t=p; p=s[p].nx[x]; s[p].cnt--;
if(s[p].cnt==) { s[t].nx[x]=-; return; }
}
} void Insert(LL num,int val)
{
int p=;
for(int i=;i>=;i--)
{
int x; LL g=(LL)(<<i); if(num&g) x=; else x=;
if(s[p].nx[x]==-) s[p].nx[x]=add();
p=s[p].nx[x]; s[p].cnt++; s[p].mx=max(s[p].mx,val);
}
} void Find(LL num)
{
int p=;
for(int i=;i>=;i--)
{
int x; LL g=(LL)(<<i); if(num&g) x=; else x=;
int y; if(X&g) y=; else y=; if(y==)
{
p=s[p].nx[x]; if(p==-) return;
if(i==) h=max(h,s[p].mx),fail=;
}
else
{
if(s[p].nx[x]!=-) h=max(h,s[s[p].nx[x]].mx),fail=;
p=s[p].nx[x^]; if(p==-) return;
if(i==) h=max(h,s[p].mx),fail=;
}
}
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%lld%d",&n,&X,&L);
scanf("%lld%lld%lld",&a[],&P,&Q);
for(int i=;i<=n;i++) a[i]=(a[i-]*P%mod+Q)%mod; sz=; s[sz].cnt=; s[sz].nx[]=s[sz].nx[]=-; sz++; for(int i=;i<=n;i++) f[i]=;
for(int i=;i<=n;i++)
{
if(i-L->=&&f[i-L-] ) Delete(a[i-L-]);
dp[i]=; a[i]=a[i]^a[i-]; if(a[i]<=X) dp[i]=;
h=; fail=; Find(a[i]); if(fail==) dp[i]=h+;
if(dp[i]!=) { Insert(a[i],dp[i]); f[i]=; }
} printf("%d\n",dp[n]);
}
return ;
}

HDU 5845 Best Division的更多相关文章

  1. 【HDU - 5845】Best Division(xor-trie、01字典树、dp)

    BUPT2017 wintertraining(15) #7E 题意 把数组A划分为k个区间,每个区间不超过L长度,每一个区间异或和之和为S.现在求:S不超过X,区间个数的最大值. 且A是这样给你的: ...

  2. 【HDU】3480 Division

    http://acm.hdu.edu.cn/showproblem.php?pid=3480 题意:一个n个元素的集合S要求分成m个子集且子集并为S,要求$\sum_{S_i} (MAX-MIN)^2 ...

  3. 【HDU 6036】Division Game (NTT+数学)

    多校1 1004 HDU-6036 Division Game 题意 有k堆石头(0~k-1),每堆n个.\(n=\prod_{i=0}^{m}p_i^{e_i}\).\(0\le m,k \le 1 ...

  4. hdu 3718 Different Division

    Different Division Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. hdu 3480 Division(斜率优化DP)

    题目链接:hdu 3480 Division 题意: 给你一个有n个数的集合S,现在让你选出m个子集合,使这m个子集合并起来为S,并且每个集合的(max-min)2 之和要最小. 题解: 运用贪心的思 ...

  6. HDU 6036 - Division Game | 2017 Multi-University Training Contest 1

    /* HDU 6036 - Division Game [ 组合数学,NTT ] | 2017 Multi-University Training Contest 1 题意: k堆石子围成一个圈,数量 ...

  7. HDU 6036 Division Game

    HDU 6036 Division Game 考虑每堆石头最多操作 $ \sum e $ 次,考虑设 $ f(x) $ 表示某一堆石头(最开始都是一样的)操作 $ x $ 次后变成了 $ 1 $ 的方 ...

  8. hdu 1034 (preprocess optimization, property of division to avoid if, decreasing order process) 分类: hdoj 2015-06-16 13:32 39人阅读 评论(0) 收藏

    IMO, version 1 better than version 2, version 2 better than version 3. make some preprocess to make ...

  9. HDU 3480 Division(斜率优化+二维DP)

    Division Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 999999/400000 K (Java/Others) Tota ...

随机推荐

  1. Java构造器的深入理解

    [构造器与方法的深入理解] 构造器的深入理解 [博主]高瑞林 [博客地址]http://www.cnblogs.com/grl214 [博客地址]http://www.cnblogs.com/grl2 ...

  2. EF 下的code fist 模式编程

    EF 分两种模式 codefirst(就是不知道数据是啥,也没有数据库)  和 database fist (数据已经设计好了) 首先打开vs  新建一个项目 创建一个控制台程序 然后 新建一个Tea ...

  3. apache2部署django以及静态文件

    django中的runserver只是一个很简单的web服务器,在开发中是不建议使用的,django在官方中建议是使用apache2等web服务器来配置,并且django会把静态文件交由apache2 ...

  4. 【1】Hover 效果收集

    各种 hover 效果  github repository>>  git 仓库 1. 背景图的 hover 效果 原页面>> githubSite>>

  5. Objective-C运行时态消息传递--拼接方法名

    做IOS开发的人都知道,Objective-C语言中方法的调用是运行时采取绑定的,在编译过程中只声明该方法的存在. 那么我们来简单说下在运行时,类的消息传递. 在运行时,每个方法如[self meth ...

  6. 删除 CentOS7 更新后产生的多余的内核

    今天更新完系统的内核,重启电脑时发现突然多了一个启动项,想删除多余的启动项,在上网查找后,找到了下面的方法,经过测试,是完全可行的.自己写下来,以便以后用到.1.# uname -a 列出系统中正在使 ...

  7. unionpay技术服务开放平台

    URL: https://open.unionpay.com/ajweb/index USER: jimingsong PWD: qweasd

  8. HTML,CSS,JS,JQ

    CSS: <style> <!--属性选择器--> .container input[type="text"][name="txt"]{ ...

  9. PHP中使用CURL之备忘(一)

    1.curl只能抓取页面的部分内容的原因分析: 错误提示:CURL transport error: transfer closed with outstanding read data remain ...

  10. 初始化git

    git config --global user.name "Firstname Lastname" git config --global user.email "yo ...