Submission #1223834

#TimeUsernameProblemLanguageResultExecution timeMemory
1223834chaeryeongWorst Reporter 3 (JOI18_worst_reporter3)C++20
100 / 100
200 ms11288 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]);
		}
	}
	map <ll, pair <ll, ll>> ranges;
	for (int i = 1; i <= n; i++) {
		if (!ranges.count(f[i])) {
			ranges[f[i]] = {i, i};
		} else {
			ranges[f[i]].second = i;
		}
	}
	while (q--) {
		ll l, r, t; cin >> t >> l >> r;
		int ans = 0;
		for (auto i : ranges) {
			ll u = (t / i.first) * i.first;
			//count x such that left <= x <= right, and u - x <= r, so x >= u - r
			ans += max(0ll, i.second.second - max(i.second.first, u - r) + 1);
			//count x such that left <= x <= right, and u - x <= l - 1, so x >= u - l + 1
			ans -= max(0ll, i.second.second - max(i.second.first, u - l + 1) + 1);
		}
		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...