#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];
int maxx = 1, pos = 0;
per[0] = 1;
for ( int i = 1; i <= n; i++ ) {
per[i] = higher( per[pos], d[i] );
if ( d[i] > maxx ) {
maxx = d[i];
pos = 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;
}
// for ( period p: periods )
// printf( "%d %d %d\n", p.per, p.l, p.r );
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1068 ms |
11344 KB |
Output is correct |
2 |
Correct |
1057 ms |
11288 KB |
Output is correct |
3 |
Correct |
1016 ms |
11284 KB |
Output is correct |
4 |
Correct |
1043 ms |
11384 KB |
Output is correct |
5 |
Correct |
1057 ms |
11300 KB |
Output is correct |
6 |
Correct |
1020 ms |
11324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
340 KB |
Output is correct |
6 |
Correct |
4 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1068 ms |
11344 KB |
Output is correct |
2 |
Correct |
1057 ms |
11288 KB |
Output is correct |
3 |
Correct |
1016 ms |
11284 KB |
Output is correct |
4 |
Correct |
1043 ms |
11384 KB |
Output is correct |
5 |
Correct |
1057 ms |
11300 KB |
Output is correct |
6 |
Correct |
1020 ms |
11324 KB |
Output is correct |
7 |
Correct |
2 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 |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
324 KB |
Output is correct |
13 |
Correct |
1047 ms |
9828 KB |
Output is correct |
14 |
Correct |
1109 ms |
9048 KB |
Output is correct |
15 |
Correct |
1099 ms |
9848 KB |
Output is correct |
16 |
Correct |
1053 ms |
9872 KB |
Output is correct |
17 |
Correct |
1195 ms |
24812 KB |
Output is correct |
18 |
Correct |
1189 ms |
28984 KB |
Output is correct |
19 |
Correct |
1164 ms |
29128 KB |
Output is correct |
20 |
Correct |
1153 ms |
28988 KB |
Output is correct |
21 |
Correct |
1173 ms |
29104 KB |
Output is correct |
22 |
Correct |
1103 ms |
29096 KB |
Output is correct |
23 |
Correct |
1104 ms |
29012 KB |
Output is correct |
24 |
Correct |
1111 ms |
29076 KB |
Output is correct |
25 |
Correct |
1020 ms |
26620 KB |
Output is correct |
26 |
Correct |
1014 ms |
26524 KB |
Output is correct |
27 |
Correct |
1098 ms |
28564 KB |
Output is correct |
28 |
Correct |
1120 ms |
28940 KB |
Output is correct |
29 |
Correct |
1098 ms |
28428 KB |
Output is correct |
30 |
Correct |
1080 ms |
28672 KB |
Output is correct |
31 |
Correct |
1097 ms |
28888 KB |
Output is correct |
32 |
Correct |
1002 ms |
25128 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |