#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 100000000000LL;
ll intersect(ll l, ll r, ll tl, ll tr){
return max(0LL, min(r, tr) - max(l, tl) + 1);
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
vector <pair <pair <int, int>, ll>> intervals;
intervals.push_back({{0, 0}, 1});
ll pos = 1;
for(int i=1; i<=n; i++){
int x;
cin >> x;
ll g = pos*((x+pos-1)/pos);
g = min(g, INF);
if(g == intervals.back().second){
pair <pair <int, int>, ll> v = intervals.back();
intervals.pop_back();
v.first.first = -i;
intervals.push_back(v);
}
else{
pair <pair <int, int>, ll> v;
v.first.first = v.first.second = -i;
v.second = g;
intervals.push_back(v);
}
pos = g;
}
while(m--){
ll t, tl, tr;
cin >> t >> tl >> tr;
ll res = 0;
for(auto c : intervals){
ll l = c.first.first;
ll r = c.first.second;
ll g = c.second;
ll dist = g*(t/g);
l += dist;
r += dist;
res += intersect(l, r, tl, tr);
}
cout << res << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
277 ms |
18712 KB |
Output is correct |
2 |
Correct |
274 ms |
18672 KB |
Output is correct |
3 |
Correct |
273 ms |
18756 KB |
Output is correct |
4 |
Correct |
273 ms |
18728 KB |
Output is correct |
5 |
Correct |
272 ms |
18772 KB |
Output is correct |
6 |
Correct |
277 ms |
18740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
277 ms |
18712 KB |
Output is correct |
2 |
Correct |
274 ms |
18672 KB |
Output is correct |
3 |
Correct |
273 ms |
18756 KB |
Output is correct |
4 |
Correct |
273 ms |
18728 KB |
Output is correct |
5 |
Correct |
272 ms |
18772 KB |
Output is correct |
6 |
Correct |
277 ms |
18740 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
299 ms |
17444 KB |
Output is correct |
14 |
Correct |
290 ms |
17860 KB |
Output is correct |
15 |
Correct |
273 ms |
16416 KB |
Output is correct |
16 |
Correct |
279 ms |
16964 KB |
Output is correct |
17 |
Correct |
388 ms |
21236 KB |
Output is correct |
18 |
Correct |
376 ms |
21280 KB |
Output is correct |
19 |
Correct |
387 ms |
21388 KB |
Output is correct |
20 |
Correct |
376 ms |
21316 KB |
Output is correct |
21 |
Correct |
373 ms |
21308 KB |
Output is correct |
22 |
Correct |
376 ms |
21444 KB |
Output is correct |
23 |
Correct |
370 ms |
21284 KB |
Output is correct |
24 |
Correct |
372 ms |
21436 KB |
Output is correct |
25 |
Correct |
280 ms |
18752 KB |
Output is correct |
26 |
Correct |
289 ms |
18756 KB |
Output is correct |
27 |
Correct |
382 ms |
21052 KB |
Output is correct |
28 |
Correct |
391 ms |
21188 KB |
Output is correct |
29 |
Correct |
416 ms |
20772 KB |
Output is correct |
30 |
Correct |
387 ms |
20900 KB |
Output is correct |
31 |
Correct |
386 ms |
21036 KB |
Output is correct |
32 |
Correct |
304 ms |
17324 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |