提交时间:2023-08-14 12:35:44
运行 ID: 98229
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int a[MAXN]; long long sum[MAXN]; int main() { int n, m, p; cin >> n >> m >> p; long long maxx = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum[i] = (sum[i - 1] + a[i]) % p; } while (m--) { int l, r; cin >> l >> r; if (r < l) { cout << 0 << '\n'; } else { cout << ((sum[r] - sum[l - 1]) % p + p) % p << '\n'; } } return 0; }