이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 500000 + 10;
const int INF  = 1e9;
int n, q;
int d[MAXN];
struct Head
{
    int idx;
    int count;
    int len;
    int get(int time, int cnt)
    {
        assert(cnt <= len);
        int jumpTimes = time / d[n];
        jumpTimes -= jumpTimes % count;
        return -(n - idx + 1) + jumpTimes * d[n] - cnt;
    }
};
std::vector <Head> st;
int countTo(int to, int time)
{
    int l = -1, r = st.size(), mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        if (st[mid].get(time, 0) > to) l = mid;
        else r = mid;
    }
    int res = 0;
    if (r != st.size()) 
    {
        res += st[r].idx;
    }
    if (l != -1)
    {
        res += std::max(0, to + 1 - st[l].get(time, st[l].len - 1));
    }
    return res;
}
void solve()
{
    std::reverse(d + 1, d + 1 + n);
    st.push_back({n, 1, 1});
    for (int i = n - 1 ; i >= 1 ; --i)
    {
        if (d[i] / (st.back().count * d[n]) + ((d[i] % (st.back().count * d[n])) > 0) > 1)
        {
            st.push_back({i, (d[i] / (st.back().count * d[n]) + ((d[i] % (st.back().count * d[n])) > 0)) * st.back().count, 1});
        } else
        {
            st.back().len++;
        }
    }
    for (int i = 1 ; i <= q ; ++i)
    {
        int l, r, pos;
        std::cin >> pos >> l >> r;
    
        int res = 0;
        res += (l <= pos && pos <= r);
        res += countTo(r, pos);
        res -= countTo(l - 1, pos);
        std::cout << res << '\n';
    }
}
void input()
{
    std::cin >> n >> q;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> d[i];
    }
}
void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}
int main()
{
    fastIOI();
    input();
    solve();
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
worst_reporter3.cpp: In function 'int countTo(int, int)':
worst_reporter3.cpp:41:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Head>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     if (r != st.size())
      |         ~~^~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |