이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
vector<pair<int,int>> a;
int cnt(int x, int t) {
int l = 0, r = a.size() - 2;
while (l < r) {
int mid = l + r + 1 >> 1;
if (a[mid].second + (t - t % a[mid].first) >= x) l = mid;
else r = mid - 1;
}
int pos = a[l].second + (t - t % a[l].first);
if (pos < x) return 0;
return min(pos - x, a[l].second - a[l+1].second-1) + (-a[l].second + 1);
}
signed main() {
int q, n;
cin >> n >> q;
int cur = 0;
a.push_back({1, 0});
for (int i = 1;i <= n; i++) {
int x;
cin >> x;
if (x > cur && cur <= INF) {
if (cur == 0) cur = x;
else cur = ((x + cur - 1) / cur) * cur;
if (cur <= INF) a.push_back({cur, -i});
}
}
a.push_back({1e18, -n - 1});
while (q--) {
int t, l, r;
cin >> t >> l >> r;
cout << cnt(l, t) - cnt(r + 1, t) << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
worst_reporter3.cpp: In function 'int cnt(int, int)':
worst_reporter3.cpp:8:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
8 | int mid = l + r + 1 >> 1;
| ~~~~~~^~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |