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

运行 ID: 98146

#include <iostream> #include <cstdio> using namespace std; typedef long long i64; const int SIZE = 1e6+5; int n, m, p; i64 a[SIZE]; namespace o1 { using :: n; using :: m; using :: p; using :: a; i64 pre[SIZE]; int l, r; int main() { for (int i = 1; i <= n; ++i) { pre[i] = pre[i - 1] + a[i]; pre[i] %= p; } while (m--) { scanf("%d%d",&l,&r); printf("%lld\n",(pre[r] - pre[l - 1]) % p); } return 0; } } namespace o2 { using :: n; using :: m; using :: p; using :: a; int l, r; i64 pre[SIZE]; int main() { for (int i = 1; i <= n; ++i) { pre[i] = pre[i - 1] + a[i] - p; } while (m--) { scanf("%d%d",&l,&r); printf("%lld\n",pre[r] - pre[l - 1]); } return 0; } } int main() { #ifdef fio freopen("test.in","r",stdin); #endif cin >> n >> m >> p; bool fga = true, fgb = true; for (int i = 1; i <= n; ++i) { scanf("%lld",a+i); if (a[i] >= p) fga = false; if (a[i] < p) fgb = false; } if (fga) { return o1::main(); } else if (fgb) { return o2::main(); } else { } return 0; }