不是啊。。不是说双栈嘛,,怎么是个**题啊。

链接:

 http://120.78.128.11/Problem.jsp?pid=3260 
 
从左到右扫一遍,把相交的区间扔到一起算,那么就变成了一个前缀后缀积的问题。。
感觉还是挺有思维难度的?(也可能是我今天降智)
写起来还是很好写的,1A了。
 #include <bits/stdc++.h>
using namespace std;
inline int read() {
int X=,w=; char c=getchar();
while (c<''||c>'') { if (c=='-') w=-; c=getchar(); }
while (c>=''&&c<='') X=(X<<)+(X<<)+c-'',c=getchar();
return X*w;
}
typedef long long ll;
ll pre[],las[];
int n,p,c[],q,a[],b[],ans[];
int main(){
n=read();p=read();
for(int i=;i<=n;i++)c[i]=read();
q=read();
for(int i=;i<=q;i++)a[i]=read(),b[i]=read();
for(int l=,r;l<=q;l=r+){
r=l;
while (a[r]<=b[l]&&r<=q)r++;
r--;
//[l,r]是分成一段
pre[] = c[b[l]];
for(int i=;b[l]-i>=a[l];i++){//左边
pre[i] = pre[i-]*c[b[l]-i]%p;
}
las[]=;
for(int i=;b[l]+i<=b[r];i++){//右边
las[i]=las[i-]*c[b[l]+i]%p;
}
for(int i=l;i<=r;i++){//统计答案
ans[i]=pre[b[l]-a[i]]*las[b[i]-b[l]]%p;
}
}
for(int i=;i<=q;i++){
printf("%d\n",ans[i]);
}
}

FJUT3260的更多相关文章

随机推荐

  1. DirectX11 With Windows SDK--06 DirectXMath数学库

    前言 xnamath.h原本是位于DirectX SDK的一个数学库,但是现在Windows SDK包含的数学库已经抛弃掉原来的xnamath.h,并演变成了现在的DirectXMath.h.其实本质 ...

  2. Dubbo学习笔记8:Dubbo的线程模型与线程池策略

    Dubbo默认的底层网络通讯使用的是Netty,服务提供方NettyServer使用两级线程池,其中 EventLoopGroup(boss) 主要用来接受客户端的链接请求,并把接受的请求分发给 Ev ...

  3. CSS三种样式

    CSS 指层叠样式表 (Cascading Style Sheets): 1 内联样式:无法复用,在元素style内写 ,很少使用: 2 内部样式:在head元素内style属性内写,此样式可以被当前 ...

  4. 出现Failed to get convolution algorithm的解决方法

    当运行卷积神经时出现了问题:Failed to get convolution algorithm. This is probably because cuDNN failed to initiali ...

  5. 「luogu2680」[NOIp2015] 运输计划

    题目大意:给定一棵n个节点的树,输入m组一条链的两个端点:把树上的某个边权改为0,求m条链长度的最大值的最小值: 一.考虑二分: 1.对于需要判断是否为可行方案的 mid,所有链长不大于 mid 的链 ...

  6. L2-001 紧急救援 (25 分) (最短路+路径打印)

    链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805073643683840 题目: 作为一个城市的应急救援队伍的负 ...

  7. css之自定义滚动条

    <div class="alertbox index-rulebox" style="display:none"> <div class=&q ...

  8. 【原创】Linux基础之iptables

    iptables 1.4.21 官方:https://www.netfilter.org/projects/iptables/index.html iptables is the userspace ...

  9. 【原创】运维基础之Docker(3)搭建私有仓库

    下载并启动registry $ docker pull registry$ docker run --name my_registry -d -p 5000:5000 -v /var/lib/regi ...

  10. Linux超级守护进程——xinetd

    Linux超级守护进程--xinetd 一 Linux守护进程 Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户.提供这些服务 ...