제출 #94596

#제출 시각아이디문제언어결과실행 시간메모리
94596aminraWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
454 ms29116 KiB
//Smaug never desolated!!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)5e5 + 7;
const int infint = (int)1e9 + 3;
const int MOD = (int)1e9 + 7;
const ll inf = (ll)1e18;
ll a[MAXN], n, tme[MAXN], Q;
ll intersect(ll u, ll v, ll a, ll b)
{
	ll mx = max(u, a);
	ll mn = min(v, b);
	if(mn >= mx)
		return mn - mx + 1;
	else
		return 0;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> Q;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	tme[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		ll tmp = (a[i] + tme[i - 1] - 1) / tme[i - 1];
		tme[i] = tme[i - 1] * tmp;
		if(tme[i] >= infint)	
			break;
	}
	int last = 0;
	vector< pair<ll, pair<ll, ll> > > v;
	v.push_back({1, {0, 0}});
	for (int i = 1; i <= n; i++)
	{
		if(tme[i] >= infint)
			break;
		if(tme[i] == tme[last])
			v.back().second.second++;
		else
			v.push_back({tme[i], {i, i}}), last = i;
	}
	for (int i = 0; i < Q; i++)
	{
		ll L, R, T;
		cin >> T >> L >> R;
		ll ans = 0;
		for (auto u : v)
		{
			ll cur = (T / u.first) * u.first;
			ll newL = 0, newR = 0;
			if(L <= cur && cur <= R)
				newL = 0, newR = cur - L;
			else
			if(cur > R)
				newL = cur - R, newR = cur - L;
			else
				newL = -1, newR = -1;
			ans += intersect(u.second.first, u.second.second, newL, newR);	
		}
		cout << ans << "\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...