#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=5e5+7;
ll T[LIM];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
T[0]=1;
rep(i, n) {
cin >> T[i+1];
ll x=(T[i+1]+T[i]-1)/T[i];
T[i+1]=x*T[i];
}
vector<pair<pair<ll,ll>,ll>>V;
ll akt=0;
rep(i, n) {
if(T[i+1]!=T[akt]) {
V.pb({{akt, i}, T[akt]});
akt=i+1;
}
}
V.pb({{akt, n}, T[akt]});
while(q--) {
ll t, l, r;
cin >> t >> l >> r;
ll ans=0;
for(auto i : V) {
ll p=t-(t%i.nd);
ll a=-i.st.nd+p, b=-i.st.st+p;
a=max(a, l);
b=min(b, r);
ans+=max(b-a+1, 0ll);
}
cout << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
22880 KB |
Output is correct |
2 |
Correct |
143 ms |
22748 KB |
Output is correct |
3 |
Correct |
143 ms |
22612 KB |
Output is correct |
4 |
Correct |
167 ms |
22728 KB |
Output is correct |
5 |
Correct |
142 ms |
22728 KB |
Output is correct |
6 |
Correct |
147 ms |
22880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
22880 KB |
Output is correct |
2 |
Correct |
143 ms |
22748 KB |
Output is correct |
3 |
Correct |
143 ms |
22612 KB |
Output is correct |
4 |
Correct |
167 ms |
22728 KB |
Output is correct |
5 |
Correct |
142 ms |
22728 KB |
Output is correct |
6 |
Correct |
147 ms |
22880 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
484 KB |
Output is correct |
13 |
Correct |
146 ms |
21336 KB |
Output is correct |
14 |
Correct |
153 ms |
21840 KB |
Output is correct |
15 |
Correct |
151 ms |
20420 KB |
Output is correct |
16 |
Correct |
150 ms |
21072 KB |
Output is correct |
17 |
Correct |
186 ms |
25296 KB |
Output is correct |
18 |
Correct |
191 ms |
25168 KB |
Output is correct |
19 |
Correct |
185 ms |
25360 KB |
Output is correct |
20 |
Correct |
179 ms |
25152 KB |
Output is correct |
21 |
Correct |
183 ms |
25168 KB |
Output is correct |
22 |
Correct |
195 ms |
25428 KB |
Output is correct |
23 |
Correct |
178 ms |
25288 KB |
Output is correct |
24 |
Correct |
201 ms |
25428 KB |
Output is correct |
25 |
Correct |
141 ms |
22608 KB |
Output is correct |
26 |
Correct |
147 ms |
22608 KB |
Output is correct |
27 |
Correct |
181 ms |
24828 KB |
Output is correct |
28 |
Correct |
205 ms |
25168 KB |
Output is correct |
29 |
Correct |
185 ms |
24608 KB |
Output is correct |
30 |
Correct |
183 ms |
24912 KB |
Output is correct |
31 |
Correct |
195 ms |
25112 KB |
Output is correct |
32 |
Correct |
143 ms |
21380 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |