提交时间:2023-08-14 12:22:01

运行 ID: 98143

#include<bits/stdc++.h> #define int long long using namespace std; const int N=1e6+5; int n,m,p,a[N],s[N]; bool fl; signed main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n>>m>>p; for(int i=1; i<=n; ++i){ cin>>a[i],s[i]=s[i-1]+a[i]; if(a[i]>p)fl=1; }int l,r,res; while(m--){ cin>>l>>r,res=s[r]-s[l-1]; if(fl)res-=p*n;else res%=p; cout<<res<<'\n'; } return 0; }