FJUT3260

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

链接:

 http://120.78.128.11/Problem.jsp?pid=3260 
 
从左到右扫一遍,把相交的区间扔到一起算,那么就变成了一个前缀后缀积的问题。。
感觉还是挺有思维难度的?(也可能是我今天降智)
写起来还是很好写的,1A了。
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 inline int read() {
 4     int X=0,w=1; char c=getchar();
 5     while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
 6     while (c>='0'&&c<='9') X=(X<<3)+(X<<1)+c-'0',c=getchar();
 7     return X*w;
 8 }
 9 typedef long long ll;
10 ll pre[1000005],las[1000005];
11 int n,p,c[1000005],q,a[1000005],b[1000005],ans[1000005];
12 int main(){
13     n=read();p=read();
14     for(int i=1;i<=n;i++)c[i]=read();
15     q=read();
16     for(int i=1;i<=q;i++)a[i]=read(),b[i]=read();
17     for(int l=1,r;l<=q;l=r+1){
18         r=l;
19         while (a[r]<=b[l]&&r<=q)r++;
20         r--;
21         //[l,r]是分成一段
22         pre[0] = c[b[l]];
23         for(int i=1;b[l]-i>=a[l];i++){//左边
24             pre[i] = pre[i-1]*c[b[l]-i]%p;
25         }
26         las[0]=1;
27         for(int i=1;b[l]+i<=b[r];i++){//右边
28             las[i]=las[i-1]*c[b[l]+i]%p;
29         }
30         for(int i=l;i<=r;i++){//统计答案
31             ans[i]=pre[b[l]-a[i]]*las[b[i]-b[l]]%p;
32         }
33     }
34     for(int i=1;i<=q;i++){
35         printf("%d\n",ans[i]);
36     }
37 }
View Code

猜你喜欢

转载自www.cnblogs.com/MXang/p/10568887.html