답안 #825966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825966 2023-08-15T09:37:17 Z borisAngelov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
17 / 100
3000 ms 53976 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1000005;

int n, q;

int a[maxn];

struct query
{
    int l;
    int k;
    int idx;

    query()
    {

    }

    query(int _l, int _k, int _idx)
    {
        l = _l;
        k = _k;
        idx = _idx;
    }
};

vector<query> queries[maxn];
int answers[maxn];

int max_inv_sum[maxn];

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> q;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }

    for (int i = 1; i <= q; ++i)
    {
        int l, r, k;
        cin >> l >> r >> k;
        queries[r].push_back(query(l, k, i));
    }

    stack<int> st;

    for (int i = 1; i <= n; ++i)
    {
        while (!st.empty() && a[st.top()] <= a[i])
        {
            st.pop();
        }

        if (!st.empty())
        {
            for (int j = 1; j <= st.top(); ++j)
            {
                max_inv_sum[j] = max(max_inv_sum[j], a[i] + a[st.top()]);
            }
        }

        for (int j = 0; j < queries[i].size(); ++j)
        {
            int l = queries[i][j].l;
            int max_sum = 0;

            for (int k = l; k <= i; ++k)
            {
                max_sum = max(max_sum, max_inv_sum[k]);

                if (max_sum > queries[i][j].k)
                {
                    break;
                }
            }

            //cout << "test " << l << ' ' << i << ' ' << max_sum << ' ' << endl;

            if (max_sum <= queries[i][j].k)
            {
                answers[queries[i][j].idx] = 1;
            }
            else
            {
                answers[queries[i][j].idx] = 0;
            }
        }

        st.push(i);
    }

    for (int i = 1; i <= q; ++i)
    {
        cout << answers[i] << "\n";
    }

    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:77:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for (int j = 0; j < queries[i].size(); ++j)
      |                         ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23820 KB Output is correct
3 Correct 11 ms 23840 KB Output is correct
4 Correct 12 ms 23828 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 12 ms 23832 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23856 KB Output is correct
9 Correct 12 ms 23824 KB Output is correct
10 Correct 11 ms 23824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23820 KB Output is correct
3 Correct 11 ms 23840 KB Output is correct
4 Correct 12 ms 23828 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 12 ms 23832 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23856 KB Output is correct
9 Correct 12 ms 23824 KB Output is correct
10 Correct 11 ms 23824 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 23 ms 23924 KB Output is correct
13 Correct 23 ms 24048 KB Output is correct
14 Correct 26 ms 24088 KB Output is correct
15 Correct 25 ms 24124 KB Output is correct
16 Correct 25 ms 24020 KB Output is correct
17 Correct 18 ms 24048 KB Output is correct
18 Correct 21 ms 24056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3063 ms 53976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3074 ms 27232 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23820 KB Output is correct
3 Correct 11 ms 23840 KB Output is correct
4 Correct 12 ms 23828 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 12 ms 23832 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23856 KB Output is correct
9 Correct 12 ms 23824 KB Output is correct
10 Correct 11 ms 23824 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 23 ms 23924 KB Output is correct
13 Correct 23 ms 24048 KB Output is correct
14 Correct 26 ms 24088 KB Output is correct
15 Correct 25 ms 24124 KB Output is correct
16 Correct 25 ms 24020 KB Output is correct
17 Correct 18 ms 24048 KB Output is correct
18 Correct 21 ms 24056 KB Output is correct
19 Execution timed out 3054 ms 36528 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23820 KB Output is correct
3 Correct 11 ms 23840 KB Output is correct
4 Correct 12 ms 23828 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 12 ms 23832 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23856 KB Output is correct
9 Correct 12 ms 23824 KB Output is correct
10 Correct 11 ms 23824 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 23 ms 23924 KB Output is correct
13 Correct 23 ms 24048 KB Output is correct
14 Correct 26 ms 24088 KB Output is correct
15 Correct 25 ms 24124 KB Output is correct
16 Correct 25 ms 24020 KB Output is correct
17 Correct 18 ms 24048 KB Output is correct
18 Correct 21 ms 24056 KB Output is correct
19 Execution timed out 3063 ms 53976 KB Time limit exceeded
20 Halted 0 ms 0 KB -