#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
vector<int> slow;
vector<ii> mv;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
slow.pb(1);
for(int i = 0; i < n; i++){
int x;
cin >> x;
slow.pb(x);
}
mv.pb({1, 1});
for(int i = 1; i < slow.size(); i++){
int px = mv.back().first;
int pt = mv.back().second;
int cx = slow[i];
// if(pt > 3e9)break;
int k = (cx - 1) / px + 1;
mv.pb({k * px, k * pt});
assert(2e18 / k > pt);
}
while(q--){
int t, x, y;
cin >> t >> x >> y;
int l = 0, r = sz(mv) - 1, low = INF, high = -INF;
while(l <= r){
int mid = (l + r) / 2;
int curr = -mid + (t / mv[mid].second) * mv[mid].first;
if(curr <= y){
low = mid;
r = mid - 1;
}
else l = mid + 1;
}
l = 0, r = sz(mv) - 1;
while(l <= r){
int mid = (l + r) / 2;
int curr = -mid + (t / mv[mid].second) * mv[mid].first;
if(x <= curr){
high = mid;
l = mid + 1;
}
else r = mid - 1;
}
if(high < low)cout << "0\n";
else cout << high - low + 1 << "\n";
}
}
Compilation message
worst_reporter3.cpp: In function 'int32_t main()':
worst_reporter3.cpp:28:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < slow.size(); i++){
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
763 ms |
15288 KB |
Output is correct |
2 |
Correct |
779 ms |
30808 KB |
Output is correct |
3 |
Correct |
805 ms |
30776 KB |
Output is correct |
4 |
Correct |
776 ms |
30852 KB |
Output is correct |
5 |
Correct |
740 ms |
30800 KB |
Output is correct |
6 |
Correct |
731 ms |
30736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
763 ms |
15288 KB |
Output is correct |
2 |
Correct |
779 ms |
30808 KB |
Output is correct |
3 |
Correct |
805 ms |
30776 KB |
Output is correct |
4 |
Correct |
776 ms |
30852 KB |
Output is correct |
5 |
Correct |
740 ms |
30800 KB |
Output is correct |
6 |
Correct |
731 ms |
30736 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
422 ms |
29392 KB |
Output is correct |
14 |
Correct |
441 ms |
29808 KB |
Output is correct |
15 |
Correct |
411 ms |
28624 KB |
Output is correct |
16 |
Correct |
431 ms |
29128 KB |
Output is correct |
17 |
Correct |
550 ms |
33364 KB |
Output is correct |
18 |
Correct |
574 ms |
33360 KB |
Output is correct |
19 |
Correct |
550 ms |
33360 KB |
Output is correct |
20 |
Correct |
539 ms |
33536 KB |
Output is correct |
21 |
Correct |
537 ms |
33328 KB |
Output is correct |
22 |
Correct |
560 ms |
33552 KB |
Output is correct |
23 |
Correct |
546 ms |
33360 KB |
Output is correct |
24 |
Correct |
553 ms |
33488 KB |
Output is correct |
25 |
Correct |
772 ms |
30668 KB |
Output is correct |
26 |
Correct |
779 ms |
31056 KB |
Output is correct |
27 |
Correct |
603 ms |
32968 KB |
Output is correct |
28 |
Correct |
573 ms |
33108 KB |
Output is correct |
29 |
Correct |
580 ms |
32708 KB |
Output is correct |
30 |
Correct |
593 ms |
32932 KB |
Output is correct |
31 |
Correct |
602 ms |
33104 KB |
Output is correct |
32 |
Correct |
541 ms |
29392 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |