#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 ) {
periods.push_back( { per[pos], pos, i - 1 } );
maxx = d[i];
pos = i;
}
if ( per[i] > MAX_T )
break;
}
periods.push_back( { per[pos], pos, n } );
if ( periods.size() > 40 )
return 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 |
1004 ms |
11576 KB |
Output is correct |
2 |
Correct |
1066 ms |
11760 KB |
Output is correct |
3 |
Correct |
996 ms |
11736 KB |
Output is correct |
4 |
Correct |
1028 ms |
11760 KB |
Output is correct |
5 |
Correct |
1071 ms |
11736 KB |
Output is correct |
6 |
Correct |
1074 ms |
11768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Runtime error |
1 ms |
340 KB |
Execution failed because the return code was nonzero |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1004 ms |
11576 KB |
Output is correct |
2 |
Correct |
1066 ms |
11760 KB |
Output is correct |
3 |
Correct |
996 ms |
11736 KB |
Output is correct |
4 |
Correct |
1028 ms |
11760 KB |
Output is correct |
5 |
Correct |
1071 ms |
11736 KB |
Output is correct |
6 |
Correct |
1074 ms |
11768 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Runtime error |
1 ms |
340 KB |
Execution failed because the return code was nonzero |
12 |
Halted |
0 ms |
0 KB |
- |