一点都不良心!!!!


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. PHP + ajax 实现异步登录验证

    login.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...

  2. sbit命令行中运行scala脚本

    一般sbit编译器采成了scala运行工具.启动sbit命令行,输入console,命令行自动切换到scala编辑器面. scala>:paste 然后手动将XXX.scala中的代码拷贝到界面 ...

  3. C# if,ifelse语句

    1,if语句的判断是根据布尔表达式的值. if语句主要有两种方式,如下 Code(1)if(boolean) do (2)if(boolean){ do } 一般大家都是用第二种方法,因为第一种方法只 ...

  4. linq 多条件查询 where 拼接+分页

    首先定义一个静态类 public static class QueryAssembly { /// <summary> /// 返回true /// </summary> // ...

  5. iOS8 【xcode6中添加pch全局引用文件】

    前沿:xcode6中去掉了pch,为了一些琐碎的头文件引用,加快了 编译速度! xcode6之前的版本建项目就自动添加了是这样的: xcode6后的版本要自己手动的添加步骤如下: 1)  2) 3) ...

  6. OC - 12.NSURLRequest与NSURLConnection

    ##NSURLRequest NSURLRequest封装了一次网络请求所需要的数据,主要封装了以下信息: 请求路径(URL) 请求方法(GET或POST) 请求头 请求体 超时参数 NSURLReq ...

  7. 专题一、ArrayList增删操作技术细节详解

    一.索引检查 1)在指定位置插入元素时,第一步都需要检查输入的指定位置是否合法 public void add(int index, E element){    rangeCheckForAdd(i ...

  8. @font-face

     /**  * jQuery.hhNewSilder 滚动图片插件  * User: huanhuan  * QQ: 651471385  * Email: th.wanghuan@gmail.com ...

  9. CSS小注意(初级)

    前言 自己的前端技术相对后台来说要薄弱了很多,这一阵子在努力的学习中,添加样式这是最简单不过的东西了,但是今天我犯了一个错误,不知道大家是不是有时候也会忽略或者做同样的事情,我觉得很大部分人不会,废话 ...

  10. File控件杂谈

    我们通常使用<input type='file'/>来实现网页中文件上传功能,用户可以通过点击file控件选择本地文件,当我们提交包含该控件的表单时,浏览器会向服务器发送用户选中的文件. ...