Submission #749113

#TimeUsernameProblemLanguageResultExecution timeMemory
749113stevancvWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
309 ms25356 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 5e5 + 2; const int inf = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, Q; cin >> n >> Q; vector<int> d(n), koef(n); for (int i = 0; i < n; i++) cin >> d[i]; koef[0] = d[0]; for (int i = 1; i < n; i++) { ll o = (d[i] - 1) / koef[i - 1]; ll u = (ll) (koef[i - 1]) * (o + 1); if (u > 1e9) { for (int zz = 0; zz < n - i; zz++) { d.pop_back(); koef.pop_back(); } break; } koef[i] = koef[i - 1] * (o + 1); } n = d.size(); vector<int> gde; gde.push_back(0); for (int i = 1; i < n; i++) if (koef[i] > koef[i - 1]) gde.push_back(i); int sz = gde.size(); while (Q--) { int t, l, r; cin >> t >> l >> r; int ans = 0; for (int ii = 0; ii < sz; ii++) { int i = gde[ii]; int kr = (ii == sz - 1 ? n : gde[ii + 1]) - 1; int w = (t / koef[i]) * koef[i]; int p = w - i - 1; int q = w - kr - 1; smax(q, l); smin(p, r); ans += max(0, min(p, r) - max(q, l) + 1); } ans += (l <= t && t <= r); cout << ans << en; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...