#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
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;
}
/*for(auto c : intervals){
cout << c.first.first << " " << c.first.second << " " << c.second << "\n";
}*/
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
252 ms |
3308 KB |
Output is correct |
2 |
Correct |
255 ms |
3308 KB |
Output is correct |
3 |
Correct |
252 ms |
3436 KB |
Output is correct |
4 |
Correct |
254 ms |
3308 KB |
Output is correct |
5 |
Correct |
259 ms |
3632 KB |
Output is correct |
6 |
Correct |
254 ms |
3436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
252 ms |
3308 KB |
Output is correct |
2 |
Correct |
255 ms |
3308 KB |
Output is correct |
3 |
Correct |
252 ms |
3436 KB |
Output is correct |
4 |
Correct |
254 ms |
3308 KB |
Output is correct |
5 |
Correct |
259 ms |
3632 KB |
Output is correct |
6 |
Correct |
254 ms |
3436 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
284 ms |
17660 KB |
Output is correct |
14 |
Correct |
268 ms |
18028 KB |
Output is correct |
15 |
Correct |
256 ms |
16640 KB |
Output is correct |
16 |
Correct |
281 ms |
17132 KB |
Output is correct |
17 |
Correct |
354 ms |
21484 KB |
Output is correct |
18 |
Correct |
357 ms |
21484 KB |
Output is correct |
19 |
Correct |
359 ms |
21612 KB |
Output is correct |
20 |
Correct |
357 ms |
21356 KB |
Output is correct |
21 |
Correct |
352 ms |
21484 KB |
Output is correct |
22 |
Correct |
354 ms |
21484 KB |
Output is correct |
23 |
Correct |
355 ms |
21356 KB |
Output is correct |
24 |
Correct |
358 ms |
21484 KB |
Output is correct |
25 |
Correct |
267 ms |
18924 KB |
Output is correct |
26 |
Correct |
268 ms |
18796 KB |
Output is correct |
27 |
Correct |
360 ms |
21100 KB |
Output is correct |
28 |
Correct |
371 ms |
21228 KB |
Output is correct |
29 |
Correct |
371 ms |
20972 KB |
Output is correct |
30 |
Correct |
371 ms |
21228 KB |
Output is correct |
31 |
Correct |
378 ms |
21228 KB |
Output is correct |
32 |
Correct |
261 ms |
17644 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |