이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct Group {
int l, r;
ll period;
};
ll d[500001];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> q;
vector<Group> groups = {{0, 0, 1}};
for (int i = 1; i <= n; i++) {
cin >> d[i];
ll p = groups.back().period;
if (d[i] <= p) groups.back().l--;
else groups.push_back({-i, -i, (d[i] + p - 1) / p * p});
}
while (q--) {
ll l, r, t;
cin >> t >> l >> r;
int ans = 0;
for (Group i : groups) {
ll mv = t / i.period * i.period;
ans += max(0ll, min(r, i.r + mv) - max(l, i.l + mv) + 1);
}
cout << ans << '\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... |