답안 #915596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915596 2024-01-24T09:12:55 Z boris_mihov Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
295 ms 23528 KB
#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;
}

Compilation message

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())
      |         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 20936 KB Output is correct
2 Correct 199 ms 20828 KB Output is correct
3 Correct 214 ms 20816 KB Output is correct
4 Correct 206 ms 20632 KB Output is correct
5 Correct 199 ms 20672 KB Output is correct
6 Correct 200 ms 20632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 20936 KB Output is correct
2 Correct 199 ms 20828 KB Output is correct
3 Correct 214 ms 20816 KB Output is correct
4 Correct 206 ms 20632 KB Output is correct
5 Correct 199 ms 20672 KB Output is correct
6 Correct 200 ms 20632 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 192 ms 19400 KB Output is correct
14 Correct 191 ms 19796 KB Output is correct
15 Correct 187 ms 18544 KB Output is correct
16 Correct 188 ms 19104 KB Output is correct
17 Correct 266 ms 23528 KB Output is correct
18 Correct 295 ms 23368 KB Output is correct
19 Correct 274 ms 23380 KB Output is correct
20 Correct 261 ms 23356 KB Output is correct
21 Correct 264 ms 23340 KB Output is correct
22 Correct 260 ms 23392 KB Output is correct
23 Correct 270 ms 23236 KB Output is correct
24 Correct 262 ms 23276 KB Output is correct
25 Correct 219 ms 20728 KB Output is correct
26 Correct 217 ms 20816 KB Output is correct
27 Correct 286 ms 22688 KB Output is correct
28 Correct 279 ms 23124 KB Output is correct
29 Correct 286 ms 23020 KB Output is correct
30 Correct 274 ms 22736 KB Output is correct
31 Correct 279 ms 23192 KB Output is correct
32 Correct 215 ms 19216 KB Output is correct
33 Correct 0 ms 344 KB Output is correct