Submission #838444

# Submission time Handle Problem Language Result Execution time Memory
838444 2023-08-27T00:08:07 Z NK_ Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
505 ms 31396 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front
 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
 
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
 
using db = long double;
 
template<class T> using pq = priority_queue<T, V<T>, less<T>>;
 
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int N, Q; cin >> N >> Q;
	vi D(N); for(auto& x : D) cin >> x;

	ll mx = 1;
	vl MUL(N+1, 1), MOVE(N+1, 1);
	for(int i = 1; i <= N; i++) {
		MOVE[i] = MOVE[i - 1];
		if (mx < D[i - 1]) MOVE[i] = D[i - 1] + ((mx - (D[i - 1] % mx)) % mx);

		ll d = (MOVE[i] + mx - 1) / mx; 
		MUL[i] = min(MOD + 0LL, MUL[i - 1] * d);
		// cout << i << " => " << MUL[i] << " - " << MOVE[i] << " - " << d << endl;

		mx = max(mx, MOVE[i]);
	}

	auto get = [&](int t, int x) {
		int lo = 0, hi = N + 1;
		while(lo < hi) {
			int mid = (lo + hi) / 2;
			// cout << lo << " <= " << mid << " <= " << hi << endl;
			ll pos = (t / MUL[mid]) * MOVE[mid] - mid;
			// cout << t << " " << mid << " => " << pos << " - " << MUL[mid] << endl;

			if (pos <= x) hi = mid;
			else lo = mid + 1;
		}
		// cout << lo << " <<>> " << hi << endl;

		return N + 1 - lo;
	};

	for(int q = 0; q < Q; q++) {
		int t, l, r; cin >> t >> l >> r;
		cout << get(t, r) - get(t, l - 1) << nl;
	}

	exit(0-0);
} 		
# Verdict Execution time Memory Grader output
1 Correct 466 ms 28604 KB Output is correct
2 Correct 469 ms 28492 KB Output is correct
3 Correct 480 ms 28648 KB Output is correct
4 Correct 505 ms 28520 KB Output is correct
5 Correct 487 ms 28504 KB Output is correct
6 Correct 466 ms 28516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 466 ms 28604 KB Output is correct
2 Correct 469 ms 28492 KB Output is correct
3 Correct 480 ms 28648 KB Output is correct
4 Correct 505 ms 28520 KB Output is correct
5 Correct 487 ms 28504 KB Output is correct
6 Correct 466 ms 28516 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 263 ms 27028 KB Output is correct
14 Correct 263 ms 27616 KB Output is correct
15 Correct 269 ms 26276 KB Output is correct
16 Correct 266 ms 26828 KB Output is correct
17 Correct 346 ms 31136 KB Output is correct
18 Correct 340 ms 31148 KB Output is correct
19 Correct 342 ms 31128 KB Output is correct
20 Correct 331 ms 31072 KB Output is correct
21 Correct 353 ms 31084 KB Output is correct
22 Correct 350 ms 31396 KB Output is correct
23 Correct 349 ms 31016 KB Output is correct
24 Correct 344 ms 31152 KB Output is correct
25 Correct 467 ms 28544 KB Output is correct
26 Correct 460 ms 28620 KB Output is correct
27 Correct 385 ms 30636 KB Output is correct
28 Correct 366 ms 30996 KB Output is correct
29 Correct 368 ms 30508 KB Output is correct
30 Correct 370 ms 30700 KB Output is correct
31 Correct 366 ms 30928 KB Output is correct
32 Correct 357 ms 27236 KB Output is correct
33 Correct 0 ms 212 KB Output is correct