一点都不良心!!!!


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. magento 常用的函数

    1.Magento eav_attribute表中source如何指定自定义数据来源  如果你引用的类名为yebihai_usermanage_model_entity_school你必须完整的给出地 ...

  2. java 用eclipse j2ee写的servlet 程序,WEB-INF下的配置文件web.xml在哪啊?谢谢!

    我用的版本是tomcat7.0,在webcontent\web-inf里只有一个空文件夹lib,写完servlet 类程序,就可以运行了,我想知道自动生成的配置文件在哪里?或者说从哪里能够看出来配置内 ...

  3. Activiti工作流引擎使用

    http://www.kafeitu.me/activiti/2012/03/22/workflow-activiti-action.html 1.简单介工作流引擎与Activiti 对于工作流引擎的 ...

  4. 20160330javaweb之session 小练习

    练习一:session 实现登录注销 package com.dzq.session.logout; import java.util.*; public class UserDao { /** * ...

  5. win7音量控制图标不见了怎么办啦?

    1.打开程序管理器(ctrl+alt+delete)2.在进程那里找到"explorer.exe",然后按结束进程(此时工具栏会消失)3.然后在文件(程序管理器左上角),点击&qu ...

  6. Python问题记录:如何处理中文网页中的多余空格

    在制作Epub电子书的时候,因为有从网络上下载的格式比较混乱的电子书,现在打算自己用Pythonc处理一下. 1.如何删除掉网页(html)中的多余空额.尤其是包含在tag(标签:span.p)当中的 ...

  7. spark-shell - 三个引号,让脚本阅读更开心

    spark-shell中可以直接编写SQL语句从数据源中加载数据. 可以利用scala语言中的多行字符串(三个引号)让SQL语句结构清晰更易于阅读. 示例: sqlContext.sql(" ...

  8. Graphviz使用简介(中文乱码的问题)

    Graphviz使用简介 graphviz是基于dot语言的绘图工具,可以画有向图.无向图.关系图.目录图.流程图等.具体作用可见它的官方网站 一些参考的网址: http://www.open-ope ...

  9. CSS 常用命名

    在前端开发中,规范使用 DIV+CSS 命名,可以增强团队合作提高开发效率,有利于页面后期的维护和优化. 1.页面结构 wrap:外套.包裹,用于最外层. wrapper:外套,用于页面外围控制整体布 ...

  10. 青瓷qici - H5小游戏 抽奖机 0 创建工程

    安装运行平台需要nodejs,具体方法请参照官方说明文档. 运行后打开了一个空空的窗口. 首先我们进行工程设置,菜单>工程>设置 菜单里面设置我们游戏的名称,到时候会显示在游戏的title ...