#include <bits/stdc++.h>
#define int long long
using namespace std;
struct period {
int per, l, r;
};
const int MAX_N = 5e5 + 1;
const int MAX_T = 2e9;
int d[MAX_N], per[MAX_N];
int higher( int x, int n ) {
return ((int)ceil( (double)n / x )) * x;
}
int lower( int x, int n ) {
return ((int)floor( (double)n / x )) * x;
}
vector<period> periods;
signed main() {
int n, q;
cin >> n >> q;
d[0] = 1;
for ( int i = 1; i <= n; i++ )
cin >> d[i];
per[0] = 1;
for ( int i = 1; i <= n; i++ )
per[i] = higher( per[i - 1], d[i] );
int i = 0;
while ( i <= n ) {
int j = i;
while ( j + 1 <= n && per[i] == per[j + 1] )
j++;
periods.push_back( { per[i], i, j } );
i = j + 1;
}
while ( q-- ) {
int t, l, r, ans = 0;
cin >> t >> l >> r;
for ( period p: periods ) {
int lp = lower( p.per, t ) - p.r, rp = lower( p.per, t ) - p.l;
ans += max( 0LL, min( rp, r ) - max( lp, l ) + 1 );
}
cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1036 ms |
13224 KB |
Output is correct |
2 |
Correct |
1050 ms |
13412 KB |
Output is correct |
3 |
Correct |
1030 ms |
13548 KB |
Output is correct |
4 |
Correct |
1037 ms |
13336 KB |
Output is correct |
5 |
Correct |
1093 ms |
13384 KB |
Output is correct |
6 |
Correct |
1036 ms |
13416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
320 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
316 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1036 ms |
13224 KB |
Output is correct |
2 |
Correct |
1050 ms |
13412 KB |
Output is correct |
3 |
Correct |
1030 ms |
13548 KB |
Output is correct |
4 |
Correct |
1037 ms |
13336 KB |
Output is correct |
5 |
Correct |
1093 ms |
13384 KB |
Output is correct |
6 |
Correct |
1036 ms |
13416 KB |
Output is correct |
7 |
Correct |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
320 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
316 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1081 ms |
11320 KB |
Output is correct |
14 |
Correct |
1040 ms |
9184 KB |
Output is correct |
15 |
Correct |
1050 ms |
11584 KB |
Output is correct |
16 |
Correct |
1037 ms |
11504 KB |
Output is correct |
17 |
Correct |
1131 ms |
26708 KB |
Output is correct |
18 |
Correct |
1121 ms |
14744 KB |
Output is correct |
19 |
Correct |
1127 ms |
14516 KB |
Output is correct |
20 |
Correct |
1250 ms |
14660 KB |
Output is correct |
21 |
Correct |
1172 ms |
14680 KB |
Output is correct |
22 |
Correct |
1128 ms |
14640 KB |
Output is correct |
23 |
Correct |
1175 ms |
15588 KB |
Output is correct |
24 |
Correct |
1134 ms |
14624 KB |
Output is correct |
25 |
Correct |
1028 ms |
26600 KB |
Output is correct |
26 |
Correct |
1008 ms |
26500 KB |
Output is correct |
27 |
Correct |
1132 ms |
17488 KB |
Output is correct |
28 |
Correct |
1197 ms |
17424 KB |
Output is correct |
29 |
Correct |
1105 ms |
17324 KB |
Output is correct |
30 |
Correct |
1123 ms |
17536 KB |
Output is correct |
31 |
Correct |
1118 ms |
17400 KB |
Output is correct |
32 |
Correct |
1038 ms |
25060 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |