# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1169253 | FIFI_cpp | Worst Reporter 3 (JOI18_worst_reporter3) | C++20 | 287 ms | 5412 KiB |
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
int n, a[N], q;
int fd(int t, int up){
int l = 0, r = n, ans = n + 1;
while (l <= r){
int m = l + r >> 1;
if (t / a[m] * a[m] - m <= up) ans = m, r = m - 1;
else l = m + 1;
}
return n - ans;
}
void solve(){
cin >> n >> q;
a[0] = 1;
for (int i = 1; i <= n; ++ i){
cin >> a[i];
a[i] = ((a[i] - 1) / a[i - 1] + 1) * a[i - 1];
}
while (q --){
int t, l, r; cin >> t >> l >> r;
cout << fd(t, r) - fd(t, l - 1) << endl;
}
}
int main(){
if (fopen("pqh.inp", "r")){
freopen("pqh.inp", "r", stdin);
freopen("pqh.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t --) solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |