Submission #891521

#TimeUsernameProblemLanguageResultExecution timeMemory
891521SharkyWorst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
477 ms25820 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<int> d(n + 1, 1); for (int i = 1; i <= n; i++) cin >> d[i]; for (int i = 1; i <= n; i++) { if (d[i] < d[i - 1]) d[i] = d[i - 1]; else d[i] = ((d[i] + d[i - 1] - 1) / d[i - 1]) * d[i - 1]; } while (q--) { int T, L, R, l = 1, r = n, idL = 0, idR = 0; cin >> T >> L >> R; // min index s.t. while (l < r) { int mid = (l + r) >> 1; int pos = (-mid + (T / d[mid]) * d[mid]); if (pos <= R) r = mid; else l = mid + 1; } if (-l + (T / d[l]) * d[l] <= R) idL = l; l = 1, r = n; while (l < r) { int mid = (l + r + 1) >> 1; int pos = (-mid + (T / d[mid]) * d[mid]); if (pos >= L) l = mid; else r = mid - 1; } if (-l + (T / d[l]) * d[l] >= L) idR = l; int add = 0; if (L <= T && T <= R) add++; // cout << idL << ' ' << idR << '\n'; if (idL != 0 && idR != 0) cout << (idR - idL + 1) + add << '\n'; else cout << add << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...