提交时间:2023-08-14 12:24:10
运行 ID: 98159
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 1e6 + 5; int n, m, p, c1, c2; int a[N], s[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> p; for(int i = 1; i <= n; i++) { cin >> a[i]; c1 += (0 <= a[i] && a[i] < p); c2 += (a[i] >= p); s[i] = s[i - 1] + a[i]; } if(c1) { for(int i = 1; i <= m; i++) { int l, r; cin >> l >> r; cout << (s[r] - s[l - 1]) % p << '\n'; } } if(c2) { for(int i = 1; i <= m; i++) { int l, r; cin >> l >> r; cout << s[r] - s[l - 1] - (r - l + 1) * p << '\n'; } } return 0; }