Submission #775069

#TimeUsernameProblemLanguageResultExecution timeMemory
775069adaawfWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
1370 ms26568 KiB
#include <iostream> using namespace std; long long int n, a[500005], f[500005]; long long int check(long long int x, long long int i) { return x / f[i] * f[i] - i; } int trya(long long int t, long long int x) { int l = 0, r = n, res = -1; while (l <= r) { int mid = (l + r) / 2; if (check(t, mid) >= x) { res = mid; l = mid + 1; } else r = mid - 1; } return res + 1; } int main() { int q; cin >> n >> q; f[0] = 1; for (int i = 1; i <= n; i++) { cin >> a[i]; f[i] = (a[i] + f[i - 1] - 1) / f[i - 1] * f[i - 1]; } for (int jj = 0; jj < q; jj++) { long long int t, l, r; cin >> t >> l >> r; if (t < l) { cout << 0 << '\n'; continue; } if (t == l) { cout << 1 << '\n'; continue; } long long int h = trya(t, l), k = trya(t, r + 1); cout << h - k << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...