#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 5e5 + 5, inf = 1e9 + 7, LG = 30;
int n, q;
int d[N], t[N];
vector<int> p[LG];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> d[i];
}
vector<int> comp = {1};
t[0] = 1;
for (int i = 1; i <= n; ++i) {
t[i] = min((long long) inf, (long long) t[i - 1] * ((d[i] - 1) / t[i - 1] + 1));
comp.push_back(t[i]);
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
for (int i = n; i >= 0; --i) {
t[i] = lower_bound(comp.begin(), comp.end(), t[i]) - comp.begin();
p[t[i]].push_back(-i);
}
auto qry = [&](vector<int> &cands, int l, int r) {
int a = lower_bound(cands.begin(), cands.end(), l) - cands.begin();
int b = upper_bound(cands.begin(), cands.end(), r) - cands.begin();
return b - a;
};
while (q--) {
int T, L, R; cin >> T >> L >> R;
int res = 0;
for (int i = 0; i < comp.size(); ++i) {
int x = T / comp[i] * comp[i], l = L - x, r = R - x;
res += qry(p[i], l, r);
}
cout << res << "\n";
}
return 0;
}
Compilation message
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i = 0; i < comp.size(); ++i) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
271 ms |
26692 KB |
Output is correct |
2 |
Correct |
275 ms |
26876 KB |
Output is correct |
3 |
Correct |
278 ms |
26692 KB |
Output is correct |
4 |
Correct |
271 ms |
26680 KB |
Output is correct |
5 |
Correct |
274 ms |
26696 KB |
Output is correct |
6 |
Correct |
276 ms |
26696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
271 ms |
26692 KB |
Output is correct |
2 |
Correct |
275 ms |
26876 KB |
Output is correct |
3 |
Correct |
278 ms |
26692 KB |
Output is correct |
4 |
Correct |
271 ms |
26680 KB |
Output is correct |
5 |
Correct |
274 ms |
26696 KB |
Output is correct |
6 |
Correct |
276 ms |
26696 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
203 ms |
25164 KB |
Output is correct |
14 |
Correct |
184 ms |
25924 KB |
Output is correct |
15 |
Correct |
181 ms |
24392 KB |
Output is correct |
16 |
Correct |
187 ms |
25156 KB |
Output is correct |
17 |
Correct |
374 ms |
29432 KB |
Output is correct |
18 |
Correct |
374 ms |
29384 KB |
Output is correct |
19 |
Correct |
379 ms |
29640 KB |
Output is correct |
20 |
Correct |
385 ms |
29384 KB |
Output is correct |
21 |
Correct |
382 ms |
29496 KB |
Output is correct |
22 |
Correct |
368 ms |
29636 KB |
Output is correct |
23 |
Correct |
378 ms |
29352 KB |
Output is correct |
24 |
Correct |
375 ms |
29128 KB |
Output is correct |
25 |
Correct |
289 ms |
27592 KB |
Output is correct |
26 |
Correct |
282 ms |
27588 KB |
Output is correct |
27 |
Correct |
378 ms |
29252 KB |
Output is correct |
28 |
Correct |
378 ms |
29252 KB |
Output is correct |
29 |
Correct |
385 ms |
29256 KB |
Output is correct |
30 |
Correct |
415 ms |
29384 KB |
Output is correct |
31 |
Correct |
402 ms |
29300 KB |
Output is correct |
32 |
Correct |
230 ms |
26308 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |