//Challenge: Accepted
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <assert.h>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
//using namespace __gnu_pbds;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
while (l != r) {cout << *l << " ";l++;}
cout << endl;
}
#define ll long long
#define ld long double
#define maxn 500005
#define mod 1000000007
#define pii pair<long long, long long>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
ll d[maxn], a[maxn];
int ans(int n, ll t, ll x) {
int lef = 0, rig = n + 1;
while (rig > lef + 1) {
int mid = (lef + rig) / 2;
ll dis = (-mid) + t - (t % a[mid]);
if (dis >= x) lef = mid;
else rig = mid;
}
return lef;
}
int main() {
io
int n, q;
cin >> n >> q;
for (int i = 1;i <= n;i++) cin >> d[i];
for (int i = 1;i <= n;i++) {
if (i == 1) a[i] = d[i];
else a[i] = ((d[i] + a[i - 1] - 1) / a[i - 1]) * a[i - 1];
}
while (q--) {
ll t, l, r;
cin >> t >> l >> r;
cout << ans(n, t, l) - ans(n, t, r + 1) + (l <= t && t <= r ? 1 : 0) << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
660 ms |
26744 KB |
Output is correct |
2 |
Correct |
680 ms |
26564 KB |
Output is correct |
3 |
Correct |
673 ms |
26528 KB |
Output is correct |
4 |
Correct |
784 ms |
26616 KB |
Output is correct |
5 |
Correct |
730 ms |
26584 KB |
Output is correct |
6 |
Correct |
673 ms |
26620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
660 ms |
26744 KB |
Output is correct |
2 |
Correct |
680 ms |
26564 KB |
Output is correct |
3 |
Correct |
673 ms |
26528 KB |
Output is correct |
4 |
Correct |
784 ms |
26616 KB |
Output is correct |
5 |
Correct |
730 ms |
26584 KB |
Output is correct |
6 |
Correct |
673 ms |
26620 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
434 ms |
25080 KB |
Output is correct |
14 |
Correct |
404 ms |
25680 KB |
Output is correct |
15 |
Correct |
430 ms |
24248 KB |
Output is correct |
16 |
Correct |
388 ms |
24872 KB |
Output is correct |
17 |
Correct |
518 ms |
29104 KB |
Output is correct |
18 |
Correct |
496 ms |
29164 KB |
Output is correct |
19 |
Correct |
490 ms |
29156 KB |
Output is correct |
20 |
Correct |
493 ms |
29064 KB |
Output is correct |
21 |
Correct |
497 ms |
29128 KB |
Output is correct |
22 |
Correct |
509 ms |
29116 KB |
Output is correct |
23 |
Correct |
480 ms |
29124 KB |
Output is correct |
24 |
Correct |
503 ms |
29344 KB |
Output is correct |
25 |
Correct |
673 ms |
26516 KB |
Output is correct |
26 |
Correct |
705 ms |
26592 KB |
Output is correct |
27 |
Correct |
565 ms |
28668 KB |
Output is correct |
28 |
Correct |
578 ms |
29068 KB |
Output is correct |
29 |
Correct |
533 ms |
28500 KB |
Output is correct |
30 |
Correct |
548 ms |
28712 KB |
Output is correct |
31 |
Correct |
556 ms |
28996 KB |
Output is correct |
32 |
Correct |
498 ms |
25212 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |