# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1261146 | mingga | Worst Reporter 3 (JOI18_worst_reporter3) | C++20 | 299 ms | 7516 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 5e5 + 7;
int n, q, a[N];
int calc(int t, int x) {
if(t <= x) return n + 1;
int l = 1, r = n, ans = n + 1;
while(l <= r) {
int m = (l + r) >> 1;
int pos = (t / a[m]) * a[m] - m;
if(pos <= x) {
ans = m;
r = m - 1;
} else l = m + 1;
}
return n - ans + 1;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> q;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(i > 1) {
a[i] = ((a[i] + a[i - 1] - 1) / a[i - 1]) * a[i - 1];
}
}
for(int i = 1; i <= q; i++) {
int l, r, t; cin >> t >> l >> r;
cout << calc(t, r) - calc(t, l - 1) << ln;
}
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
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... |