#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q; cin>>n>>q;
int d[n + 1];
for (int i = 1; i <= n; i++){
cin>>d[i];
}
int k[n + 1];
k[0] = 0; k[1] = d[1];
for (int i = 2; i <= n; i++){
k[i] = ceil(1.0 * d[i] / k[i - 1]) * k[i - 1];
}
int all[n + 1], S = 0;
for (int i = 1; i <= n; i++){
if (k[i] != k[i - 1]){
all[++S] = i;
}
}
all[++S] = n + 1;
while (q--){
int t, l, r, L, R; cin>>t>>l>>r;
int out = (l <= t && t <= r), p = t - 1;
for (int i = 1; i + 1 <= S; i++){
L = all[i]; R = all[i + 1] - 1;
int f = (p + L) / k[L], l1 = max(l, f * k[L] - R), r1 = min(r, f * k[L] - L);
out += max(0, (r1 - l1 + 1));
p = (f * k[L] - R) - 1;
}
cout<<out<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
24656 KB |
Output is correct |
2 |
Correct |
149 ms |
24556 KB |
Output is correct |
3 |
Correct |
156 ms |
24524 KB |
Output is correct |
4 |
Correct |
151 ms |
24696 KB |
Output is correct |
5 |
Correct |
146 ms |
24656 KB |
Output is correct |
6 |
Correct |
146 ms |
24664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
24656 KB |
Output is correct |
2 |
Correct |
149 ms |
24556 KB |
Output is correct |
3 |
Correct |
156 ms |
24524 KB |
Output is correct |
4 |
Correct |
151 ms |
24696 KB |
Output is correct |
5 |
Correct |
146 ms |
24656 KB |
Output is correct |
6 |
Correct |
146 ms |
24664 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
187 ms |
23112 KB |
Output is correct |
14 |
Correct |
159 ms |
23780 KB |
Output is correct |
15 |
Correct |
147 ms |
22352 KB |
Output is correct |
16 |
Correct |
159 ms |
22884 KB |
Output is correct |
17 |
Correct |
232 ms |
27152 KB |
Output is correct |
18 |
Correct |
231 ms |
27204 KB |
Output is correct |
19 |
Correct |
228 ms |
27204 KB |
Output is correct |
20 |
Correct |
226 ms |
27088 KB |
Output is correct |
21 |
Correct |
216 ms |
27220 KB |
Output is correct |
22 |
Correct |
220 ms |
27220 KB |
Output is correct |
23 |
Correct |
219 ms |
27408 KB |
Output is correct |
24 |
Correct |
219 ms |
27220 KB |
Output is correct |
25 |
Correct |
156 ms |
24988 KB |
Output is correct |
26 |
Correct |
150 ms |
24736 KB |
Output is correct |
27 |
Correct |
221 ms |
26668 KB |
Output is correct |
28 |
Correct |
232 ms |
26964 KB |
Output is correct |
29 |
Correct |
223 ms |
26516 KB |
Output is correct |
30 |
Correct |
233 ms |
26704 KB |
Output is correct |
31 |
Correct |
228 ms |
26968 KB |
Output is correct |
32 |
Correct |
149 ms |
23196 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |