一点都不良心!!!!


AK 快乐

爆零快乐!!!


1、

Avalue
512mb 1s
规定一个区间的价值为这个区间中所有数 and 起来的值与这个区间所有数 or 起
来的值的乘积。
例如 3 个数 2,3,6。它们 and 起来的值为 2, or 起来的值为 7,这个区间对答
案的贡献为 2*7=14。
现在有一个 n 个数的序列, 想知道所有 n*(n+1)/2 个区间的贡献的和对
1000000007 取模后的结果是多少。
例如当这个序列为{3,4,5}时,那么区间[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]的贡献
分别为 9,0,0,16,20,25。
Input
第一行一个数 n
接下来一行 n 个数 ai,表示这 n 个数(0<=ai<=10^9)。
Output
一行表示答案。
Input
3
4 5
Output
70
limit
%30 n<=1000
%100 n<=100000

我打的是nlog^2 拆位树状数组维护,f[i]表示区间i~现在循环到的点,的&值,g[i]表示|值。

然后记录最后连续有多少个1或者0,然后区间修改f和g。。

【慢且错 不说话。。

正解是,不用拆位,也是维护f,g,然后当前f和g的不同的值只有logn个,并且是单调的,然后说可以用链表?[我觉得是单调队列啊ORZ。。

这样就nlogn了。。。

要不要放我的垃圾代码:

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 100010
#define Mod 1000000007
#define LL long long LL a[Maxn];
LL f[][Maxn],g[][Maxn];
LL ct[],lt[];
LL n; void add(LL x,LL l,LL r,LL c)
{
if(l>r) return;
c%=Mod;
// printf("%lld %lld %lld %lld\n",x,l,r,c);
for(LL i=l;i<=n;i+=i&(-i))
f[x][i]=(f[x][i]+c)%Mod,g[x][i]=(g[x][i]+l*c)%Mod;
r++;
for(LL i=r;i<=n;i+=i&(-i))
f[x][i]=(f[x][i]+Mod-c)%Mod,g[x][i]=(g[x][i]+Mod-(r*c)%Mod)%Mod;
} LL gsum(LL x,LL l,LL r)
{
if(l>r) return ;
// printf("ask:%lld %lld %lld ",x,l,r);
LL ans=;
for(LL i=r;i>=;i-=i&(-i))
ans=(ans+(r+)*f[x][i]-g[x][i])%Mod;
l--;
for(LL i=l;i>=;i-=i&(-i))
ans=(ans-(l+)*f[x][i]+g[x][i])%Mod;
// printf("%lld\n",ans);
ans=(ans%Mod+Mod)%Mod;
return ans;
} int main()
{
LL ans=;
scanf("%lld",&n);
for(LL i=;i<=n;i++) scanf("%lld",&a[i]);
memset(f,,sizeof(f));
memset(g,,sizeof(g));
for(LL i=;i<=;i++) lt[i]=-,ct[i]=n+;
LL sum=;
for(LL i=;i<=n;i++)
{
for(LL j=;j<=;j++)
{
LL y=a[i]&(1LL<<j-);
if(y==)
{
if(lt[j]!=)
{
sum=sum-((1LL<<j-)*gsum(,ct[j],i-))%Mod;
sum=(sum%Mod+Mod)%Mod;
// printf("sum=%lld\n",sum);
// add(2,ct[j],i-1,-(1LL<<j-1)*gsum(1,ct[j],i-1));
add(,ct[j],i-,-(1LL<<j-));
lt[j]=;ct[j]=i;
}
}
else
{
if(lt[j]!=)
{ sum=sum+((1LL<<j-)*gsum(,ct[j],i-))%Mod;
sum=(sum%Mod+Mod)%Mod;
// printf("sum=%lld\n",sum);
// add(2,ct[j],i-1,(1LL<<j-1)*gsum(0,ct[j],i-1));
add(,ct[j],i-,(1LL<<j-));
lt[j]=;ct[j]=i;
}
}
}
add(,i,i,a[i]);add(,i,i,a[i]);
sum=(sum+a[i]*a[i])%Mod;
//add(2,i,i,(a[i]*a[i])%Mod);
ans=(ans+sum)%Mod;
// printf("sum=%lld\n",sum);
// ans=(ans+gsum(2,1,i))%Mod;
// printf("ans=%lld\n",ans);
ans=(ans%Mod+Mod)%Mod;
}
printf("%lld\n",ans);
return ;
}

真的好丑的code的说。。


2、

Sample Input
3 50
Sample Output
2

数位DP,数位DP,我打的数位DP太垃圾了,,又慢有错ORZ。。

不会告诉你我现在还没调出来,放弃治疗。。。

大数据还是错,应该是中间爆了吧ORZ。。。

233经过GDXB提点,终于AC了。。。。qpow爆了ORZ。。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
// #define Mod 1000000007
#define LL long long const LL Mod= ; LL n,p;
LL f[][][],g[][][];
LL get_ans1(int x,int fl1,int fl2)
{
if(x==) return ;
LL ans=;
LL y=(n&(1LL<<x-));
if(y!=) y=;
// if(!fl1&&!fl2&&f[x]!=-1) return f[x];
if(f[x][fl1][fl2]!=-) return f[x][fl1][fl2];
LL add=(1LL<<x-)%Mod,ad1=(n&((1LL<<x-)-))+;
if(y==)
{
ans=(ans+get_ans1(x-,,fl2)+add*add)%Mod; //0 -> 1
if(fl1) add=ad1;
add%=Mod;
ans=(ans+get_ans1(x-,fl1,)+((1LL<<x-)%Mod)*add)%Mod;//1 -> 0
}
else //
{
if(!fl1) ans=(ans+get_ans1(x-,fl1,fl2)+add*add)%Mod; //1->0
if(fl1) add=(n&((1LL<<x-)-))+;
add%=Mod;
if(!fl2) ans=(ans+get_ans1(x-,fl1,fl2)+add*((1LL<<x-)%Mod))%Mod;//0->1
else ans=(ans+get_ans1(x-,fl1,fl2))%Mod;//0->0
}
f[x][fl1][fl2]=ans;
// if(!fl1&&!fl2) f[x]=ans;
return ans;
} LL qpow(LL x,LL b)
{
x%=Mod;
LL ans=;
while(b)
{
if(b&) ans=(ans*x)%Mod;
x=(x*x)%Mod;
b>>=;
}
return ans;
} LL get_ans2(int x,int fl1,int fl2)
{
if(x==) return ;
LL ans=;
LL y=(n&(1LL<<x-));
if(y!=) y=;
// if(!fl1&&!fl2&&g[x]!=-1) return g[x];
if(g[x][fl1][fl2]!=-) return g[x][fl1][fl2];
LL ad1=1LL<<x-,ad2=(n&((1LL<<x-)-))+,add=ad1;
ad1%=Mod;ad2%=Mod;add%=Mod;
if(y==)
{
if(fl2) add=ad2;add%=Mod;
ans=(ans+get_ans2(x-,,fl2)+((ad1*add)%Mod)*((1LL<<x-)%Mod))%Mod; //0 -> 1
ans=(ans+get_ans2(x-,,))%Mod; //0 -> 0
// if(fl1) add=(n&((1<<x-1)-1))+1;
add=ad1;
add%=Mod;
if(fl1) add=ad2;
add%=Mod;
ans=(ans+get_ans2(x-,fl1,)+((add*ad1)%Mod)*((1LL<<x-)%Mod))%Mod;//1 -> 0
ans=(ans+get_ans2(x-,fl1,fl2))%Mod;//1 -> 1
}
else //
{
if(!fl1)
{
if(!fl2) ans=(ans+get_ans2(x-,fl1,fl2))%Mod; //1->1
if(fl2) add=ad2;add%=Mod;
ans=(ans+get_ans2(x-,fl1,fl2)+((ad1*add)%Mod)*((1LL<<x-)%Mod))%Mod; //1->0
}
// if(fl1) add=(n&((1<<x-1)-1))+1;
add=ad1;
if(fl1) add=ad2;
add%=Mod;
if(!fl2) ans=(ans+get_ans2(x-,fl1,fl2)+((add*ad1)%Mod)*((1LL<<x-)%Mod))%Mod;//0->1
ans=(ans+get_ans2(x-,fl1,fl2))%Mod;//0->0
}
// if(!fl1&&!fl2) g[x]=ans;
ans%=Mod;
g[x][fl1][fl2]=ans;
return ans;
} int main()
{
int mx=;
scanf("%lld%lld",&n,&p);
LL now=n,d,dd;
while(now) mx++,now/=;
memset(f,-,sizeof(f));
n--;
LL a1=get_ans1(mx,,),ans=,a2;
// printf("---%lld\n",a1);
d=qpow(,Mod-);dd=qpow(n+,Mod-);
// ans=(ans+((a1*p)%Mod)*(qpow(100,Mod-2)*qpow(n,Mod-2))%Mod)%Mod;
a1=( ((d*p)%Mod)*((a1*dd)%Mod) )%Mod;
// printf("%lld\n",a1);
ans=(ans+a1)%Mod;
// printf("%lld\n",ans); memset(g,-,sizeof(g));
a2=get_ans2(mx,,);
// printf("---%lld\n",a2);
n++;
d=qpow(,Mod-);dd=qpow(((n%Mod)*(n%Mod))%Mod,Mod-);
// ans=(ans+(a2*(100-p)%Mod)*(qpow(100,Mod-2))*qpow(n*n,Mod-2)%Mod)%Mod;
a2=( ((d*(-p))%Mod)* ((a2*dd)%Mod) )%Mod;
ans=(ans+a2)%Mod; // ans=(ans%Mod+Mod)%Mod;
printf("%lld\n",ans);
return ;
}

无视我的调试真的好丑。。


3、

Sample Input
5 3
1 2
1 3
2 4
4 5
2 2
4 1
2 3
Sample Output
313
HINT
1<=P<=N
1<=K<=N
%30
N<=2000
Q<=2000
%100
N<=100000
Q<=100000

啊,可持久化。。。

就是先算b在a上面,这个直接算

然后就是b在c下面,那么就是a->b->c这条链

然后对于dis[a,c]>=k 那么b有k个位置

对于dis[a,c]<k 有dis[a,c]个位置

算出dfs序,然后就是询问区间小于等于k的东西的值

我打的是字母树。。。

啊啊啊数据开小了就 开心了!!真开心!!!

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 200010
#define Maxd 30 struct node
{
int x,y,next;
}t[Maxn*];int len;
int first[Maxn]; void ins(int x,int y)
{
t[++len].x=x;t[len].y=y;
t[len].next=first[x];first[x]=len;
} int dep[Maxn],sm[Maxn],dfn[Maxn],rt[Maxn],cnt=;
void dfs(int x,int f)
{
dfn[x]=++cnt;dep[dfn[x]]=dep[dfn[f]]+;
rt[dfn[x]]=dfn[x];sm[dfn[x]]=;
for(int i=first[x];i;i=t[i].next) if(t[i].y!=f)
{
int y=t[i].y;
dfs(y,x);
sm[dfn[x]]+=sm[dfn[y]];
rt[dfn[x]]=rt[dfn[y]];
}
} int rrt[Maxn];
struct hp
{
int lc,rc,ct,f;
}tr[Maxn*];
int tot=; void upd(int x)
{
tr[x].lc=tr[x].rc=tr[x].ct=;
} void build()
{
int lt;
tr[].lc=tr[].rc=tr[].ct=;
rrt[]=;
for(int i=;i<=cnt;i++)
{
lt=rrt[i-];
rrt[i]=++tot;
int now=rrt[i];
int z=dep[i];
for(int j=Maxd;j>=;j--)
{
int x=(z&(<<j-));
if(x!=) x=;
if(x==)
{
tr[now].lc=++tot;upd(tot);
tr[now].rc=tr[lt].rc;
lt=tr[lt].lc;
tr[tot].ct=tr[lt].ct+;
tr[tot].f=tr[lt].f+z;
now=tot;
}
else
{
tr[now].rc=++tot;upd(tot);
tr[now].lc=tr[lt].lc;
lt=tr[lt].rc;
tr[tot].ct=tr[lt].ct+;
tr[tot].f=tr[lt].f+z;
now=tot;
}
}
}
} int sum;
int query(int l,int r,int x)
{
sum=;int ans=;
l=rrt[l-],r=rrt[r];
for(int i=Maxd;i>=;i--)
{
int y=x&(<<i-);
if(y!=) y=;
if(y==)
{
r=tr[r].lc;
l=tr[l].lc;
}
else
{
sum+=tr[tr[r].lc].ct-tr[tr[l].lc].ct;
ans+=(tr[tr[r].lc].f-tr[tr[l].lc].f);
r=tr[r].rc;
l=tr[l].rc;
}
}
return ans;
} int main()
{
int n,q;
scanf("%d%d",&n,&q);
len=;
memset(first,,sizeof(first));
for(int i=;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
ins(x,y);ins(y,x);
}
dep[]=;
dfs(,);
build();
for(int i=;i<=q;i++)
{
int p,k,ans=;
scanf("%d%d",&p,&k);
if(dep[dfn[p]]->=k) ans+=k*(sm[dfn[p]]-);
else ans+=(dep[dfn[p]]-)*(sm[dfn[p]]-); ans+=query(dfn[p]+,rt[dfn[p]],k++dep[dfn[p]]);
ans+=k*(sm[dfn[p]]--sum)-dep[dfn[p]]*sum-sum; printf("%d\n",ans);
}
return ;
}

改数据范围就A了smg!!!

垃圾的人生!!!坎坷!!!

2016-11-06 17:33:10

【良心noip膜你赛】总结的更多相关文章

  1. [SinGuLaRiTy] NOIP 膜你赛-Day 2

    [SinGuLaRiTy-1031] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 对于所有题目: Time Limit: 1s | Mem ...

  2. [SinGuLaRiTy] NOIP膜你赛-Day 1

    [SinGuLRiTy-1022] Copyright (c) SinGuLaRITy 2017. All Rights Reserved.  对于所有题目:Time Limit:1s || Memo ...

  3. LK的NOIP膜拟赛

    T1 Learn to 签到 [题目描述] 希希最喜欢二进制了.希希最喜欢的运算是\(\wedge\). 希希还喜欢很多\(01\)序列.这些序列一共有\(n\)个,每个的长度为\(m\). 希希有一 ...

  4. cdcqの省选膜你赛

    cdcqの省选膜你赛 比赛当天因为在杠hnoi2016的大数据结构没有参加,今天补了一下.挺好玩的虽然不看一句话题意的话真的卡读题 此生无悔入东方,来世愿生幻想乡 2651. 新史「新幻想史 -现代史 ...

  5. NOIP前模拟赛总结

    NOIP前模拟赛总结 from 2018.10.7 to ??? Date Name Score(Rank) Problems 2018.10.7 McfXH AK Contest 42(?) 期望得 ...

  6. NOIP 膜你题 DAY2

    NOIp膜你题   Day2 duliu 出题人:ZAY     题解 这就是一道组合数问题鸭!!!  可是泥为什么没有推出式子!! 首先我们知道的是 m 盆花都要摆上,然后他们的顺序不定(主人公忘记 ...

  7. NOIP一系列模拟赛小结

    NOIP越发接近了,于是自己也跟着机房的几位师兄一起做了几次NOIP模拟赛,收获颇多. #1-T1:求点集中的点能否只用三条与坐标轴平行的直线就能全部被经过,其实只要将横纵坐标排序后逐个点检查下就行. ...

  8. EZ 2018 01 14 2018noip第四次膜你赛

    这次惨烈的炸了个精光(只有20),然后对我的OI想法造成了巨大的转折. (以上有点作,其实我只是再也不用vector存图了而已(用邻接表)) 难度很不均匀,而且题型很狗(还有结论题???) T1 坑人 ...

  9. JXOJ 9.7 NOIP 放松模拟赛 总结

    比赛链接 T1 数数 题意:有a个红球,b个黄球,c个蓝球,d个绿球排成一列,求任意相邻不同色的排列的数目 ​ 1 <= a , b, c, d <= 30 答案对1e9 + 7 取膜 用 ...

随机推荐

  1. samba服务器与远程登录ssh

    作者:相思羽  出处:http://www.cnblogs.com/xiang-siyu 欢迎转载,也请保留这段声明.谢谢! deepin安装与配置samba服务器 安装  apt-get insta ...

  2. jquery登录验证插件

    最近写了个登录验证的jquery插件,其中功能还不是很完善,需要进一步改进,先放出来看看先. /** * 功能描述:本模块实现普通网站登录验证,以后可以添加二维码验证,以及第三方帐号登录验证 * 关联 ...

  3. Java对象与Json之间的转换

    使用Jackson的ObjectMapper对象的readValue和writeValueAsString方法可以进行转换. 对于简单基本类型或String类型的对象,使用上述方法可以满足. 但是如果 ...

  4. DevExpress GridControl 列中显示图片

    一.GridControl 的Columns中添加列 1.列名:FieldName命名为img 2.类型:ColumnEdit属性中 选择PictureEdit类型(RepositoryItemPic ...

  5. magento 常用方法集锦

    1,获得store的配置变量 Mage::getStoreConfig('sectionname/groupname/fields'); 1 Mage::getStoreConfig('section ...

  6. linux的终端,网络虚拟终端,伪终端(转)

    转自http://www.xuebuyuan.com/877887.html 2013年09月07日 ⁄ 综合 ⁄ 共 4047字 ⁄ 字号 小 中 大 ⁄ 评论关闭 Linux上许多网络服务应用,如 ...

  7. 实现View弹性滑动例子

    弹性滑动原理 将一次大的滑动非为若干次小的滑动,并在一个时间段内完成.有一种顺畅的感觉更-好的用户体验 实现方式很多种,包括用Scroller.动画.延时策略. 使用Handler实现弹性滑动 效果可 ...

  8. 不允许对索引显式地使用 DROP INDEX,该索引正用于 UNIQUE KEY

    [转载]http://blog.csdn.net/w87875251l/article/details/7929657 不允许对索引显式地使用 DROP INDEX,该索引正用于 UNIQUE KEY ...

  9. php常用正则表达式函数

    执行一个正则表达式匹配: preg_match($pattern, $subject, [array &$matches]); 最多匹配一次,返回值0或1,把第一次匹配到的结果放入$match ...

  10. ios NSMethodSignature and NSInvocation 消息转发

    1.首先获取消息转发时连个函数内部具体内容 MARK:这里是拿[@"xxxxx" length]调用拿来举例说明 (lldb) po signature <NSMethodS ...