제출 #1329310

#제출 시각아이디문제언어결과실행 시간메모리
1329310mat_jurWorst Reporter 3 (JOI18_worst_reporter3)C++20
100 / 100
243 ms13236 KiB
#include "bits/stdc++.h"
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";}
#define debug(X) cerr << "["#X"]: " << X << '\n';
#else 
#define cerr if(0)cout
#define debug(X) ;
#endif
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define ssize(x) int(x.size())
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int n, q;
	cin >> n >> q;
	vector<int> d(n);
	for (int &x : d) cin >> x;

	vector<ll> c(n+1), l(n+1);
	vector<int> idx, w;

	c[0] = 1;
	l[0] = 1;

	idx.eb(0);
	w.eb(1);

	for (int i = 1; i <= n; ++i) {
		ll k = ll(d[i-1] + l[i-1] - 1) / l[i-1];
		l[i] = l[i-1] * k;
		c[i] = c[i-1] * k;
		if (k == 1) w.back()++;
		else {
			idx.eb(i);
			w.eb(1);
		}
	}

	debug(idx);
	debug(w);

	auto cnt = [&](int t, int r) {
		int res = 0;
		for (int i = 0; i < ssize(idx); ++i) {
			int k = idx[i];
			ll pk = ll(t / c[k]) * l[k] - k;

			res += max(0, int(min(pk, ll(r)) - (pk - w[i] + 1) + 1));
		}

		return res;
	};

	while (q--) {
		int t, l, r;
		cin >> t >> l >> r;
		cout << cnt(t, r) - cnt(t, l-1) << '\n';
	}
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...