Submission #1223823

#TimeUsernameProblemLanguageResultExecution timeMemory
1223823chaeryeongWorst Reporter 3 (JOI18_worst_reporter3)C++20
12 / 100
2095 ms8268 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve () {
	int n, q; cin >> n >> q;
	vector <ll> d(n + 1, 0), f(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> d[i];
	}
	f[1] = d[1];
	for (int i = 2; i <= n; i++) {
		if (d[i] <= f[i - 1]) {
			f[i] = f[i - 1];
		} else {
			f[i] = f[i - 1] * ((d[i] + f[i - 1] - 1) / f[i - 1]);
		}
	}
	while (q--) {
		int l, r, t; cin >> t >> l >> r;
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			if ((t / f[i]) * f[i] - i <= r) {
				ans++;
			}
		}
		for (int i = 1; i <= n; i++) {
			if ((t / f[i]) * f[i] - i <= l - 1) {
				ans--;
			}
		}
		ans += t >= l && t <= r;
		cout << ans << '\n';
	}
}
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	int tc = 1; //cin >> tc;
	while (tc--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...