提交时间:2023-08-14 11:59:46

运行 ID: 98088

#include<bits/stdc++.h> #define ll long long using namespace std; int n, m, p, l, r, x, opt=1; ll ans, sum[1000006]; inline int read() { register char c; register bool flag = false; register int ret = 0; for(c=getchar(); c==' '||c=='\n'; c=getchar()); for(; c!=' '&&c!='\n'; c=getchar()) { if(c == '-') flag = true; else ret = (ret<<3)+(ret<<1)+c-'0'; } if(flag == false) return ret; else return (0-ret); } int main() { // freopen("programme.in", "r", stdin); // freopen("programme.out", "w", stdout); n = read(), m = read(), p = read(); for(register int i=1; i<=n; i++) { x = read(); if(x >= p) opt = 2; sum[i] = sum[i-1]+x; } if(opt == 1) { while(m--) { l = read(), r = read(); printf("%lld\n", (sum[r]-sum[l-1])%p); } } else { while(m--) { l = read(), r = read(); printf("%lld\n", (sum[r]-sum[l-1])-(ll)p*(r-l+1)); } } return 0; }