이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 500000;
int N, Q;
int D[N_MAX + 2];
ll F[N_MAX + 2];
ll get_pos (int t, int i) {
return (t / F[i]) * F[i] - i;
}
int cnt_after (int t, int x) {
int l = -1, r = N;
while (l < r) {
int mid = (l + r + 1) / 2;
if (get_pos(t, mid) >= x) {
l = mid;
} else {
r = mid - 1;
}
}
return l + 1;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> Q;
F[0] = 1;
for (int i = 1; i <= N; i++) {
cin >> D[i];
F[i] = F[i - 1] * ((D[i] + F[i - 1] - 1) / F[i - 1]);
}
while (Q--) {
int t, l, r;
cin >> t >> l >> r;
cout << cnt_after(t, l) - cnt_after(t, r + 1) << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |