Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
98163 wzj33300 早凉的程序2 C++ 运行超时 40 4000 MS 12968 KB 2934 2023-08-14 12:24:24

Tests(5/8):


#include <bits/stdc++.h> using namespace std; #define rep(i, s, n) for (int i = (s); i <= (n); ++i) #define all_(s, n) (s) + 1, (s) + (n) + 1 typedef long long ll; ll n, m, p; int a[1000005]; ll suma[1000005]; bool b[1000005]; bool sub0 = 1, sub1 = 1, sub2 = 1, sub3 = 1; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> p; rep(i, 1, n) { cin >> a[i]; if (a[i] < p) sub1 = 0; if (a[i] < 0 || a[i] >= p) sub0 = 0; if (i != 1 && a[i - 1] > a[i]) sub2 = 0; if (i != 1 && a[i - 1] < a[i]) sub3 = 0; if (a[i] >= p) b[i] = 1; suma[i] = suma[i - 1] + a[i]; } if (sub0) { while (m--) { int l, r; cin >> l >> r; cout << (suma[r] - suma[l - 1]) % p << endl; } return 0; } if (sub1) { while (m--) { int l, r; cin >> l >> r; cout << suma[r] - suma[l - 1] - p * (r - l + 1) << endl; } return 0; } if (sub2) { int w = lower_bound(all_(a, n), p) - a; while (m--) { int l, r; cin >> l >> r; int ww = lower_bound(suma + l, suma + r + 1, suma[l - 1]) - suma; if (ww == r + 1) { cout << suma[ww - 1] - suma[l - 1] << endl; continue; } ll cs = suma[ww] - suma[l - 1]; if (cs >= p) cs -= p; l = ww + 1; if (l > r) { cout << cs << endl; continue; } if (l < w && w <= r) { cout << (cs + suma[w - 1] - suma[l - 1]) % p + suma[r] - suma[w - 1] - p * (r - w + 1) << endl; } else if (r < w) { cout << (cs + suma[r] - suma[l - 1]) % p << endl; } else if (l >= w) { cout << (suma[r] - suma[l - 1] + cs) - p * (r - l + 1) << endl; } } return 0; } if (sub3) { int w = lower_bound(all_(a, n), p, greater<int>()) - a; while (m--) { int l, r; cin >> l >> r; if (l < w && w <= r) { cout << (suma[w - 1] - suma[l - 1]) - p * (w - l) + (suma[r] - suma[w - 1]) % p << endl; } else if (r < w) { cout << (suma[r] - suma[l - 1]) - p * (r - l + 1) << endl; } else if (l >= w) { cout << (suma[r] - suma[l - 1]) % p << endl; } } return 0; } while (m--) { int l, r; cin >> l >> r; ll sum = 0; rep(i, l, r) { sum += a[i]; if (sum >= p) sum -= p; } cout << sum << endl; } return 0; }


测评信息: