提交时间:2023-08-14 13:09:17
运行 ID: 98249
#include<bits/stdc++.h> #define N 100010 #define int long long using namespace std; int n,m,p,l,r,flg; int a[N],s[N]; signed main(){ cin>>n>>m>>p; for(int i=1;i<=n;i++) cin>>a[i],s[i]=s[i-1]+a[i]; if(a[1]>=p) flg=1; while(m--){ cin>>l>>r; int ans=s[r]-s[l-1]; if(flg) cout<<ans-p*(r-l+1)<<endl; else cout<<ans%p<<endl; } return 0; }