답안 #554889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554889 2022-04-29T14:25:12 Z Tien_Noob Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
929 ms 96312 KB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 1e6;
vector<int> ask[N + 1];
int l[N + 1], k[N + 1], res[N + 1], a[N + 1], n, m;
stack<int> st;
struct FenwickTree
{
    int Tree[N + 1];
    void add(int pos, int val)
    {
        for (; pos > 0; pos -= (pos & (-pos)))
        {
            Tree[pos] = max(Tree[pos], val);
        }
    }
    int get(int pos)
    {
        int ret = 0;
        for (; pos <= n; pos += (pos & (-pos)))
        {
            ret = max(ret, Tree[pos]);
        }
        return ret;
    }
} tree;
void read()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= m; ++ i)
    {
        int r;
        cin >> l[i] >> r >> k[i];
        ask[r].push_back(i);
    }
}
void solve()
{
    for (int i = 1; i <= n; ++ i)
    {
        while(!st.empty() && a[i] >= a[st.top()])
        {
            st.pop();
        }
        if (!st.empty())
        {
            tree.add(st.top(), a[i] + a[st.top()]);
        }
        for (int j : ask[i])
        {
            res[j] = (tree.get(l[j]) <= k[j]);
        }
        st.push(i);
    }
    for (int i = 1; i <= m; ++ i)
    {
        cout << res[i] << '\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 15 ms 23832 KB Output is correct
7 Correct 14 ms 23848 KB Output is correct
8 Correct 13 ms 23824 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 14 ms 23832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 15 ms 23832 KB Output is correct
7 Correct 14 ms 23848 KB Output is correct
8 Correct 13 ms 23824 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 14 ms 23832 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 14 ms 24076 KB Output is correct
13 Correct 17 ms 24020 KB Output is correct
14 Correct 18 ms 24148 KB Output is correct
15 Correct 15 ms 24076 KB Output is correct
16 Correct 14 ms 24088 KB Output is correct
17 Correct 15 ms 24084 KB Output is correct
18 Correct 15 ms 24020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 929 ms 95148 KB Output is correct
2 Correct 916 ms 96168 KB Output is correct
3 Correct 900 ms 96124 KB Output is correct
4 Correct 912 ms 96312 KB Output is correct
5 Correct 832 ms 92268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 29484 KB Output is correct
2 Correct 61 ms 28748 KB Output is correct
3 Correct 62 ms 28920 KB Output is correct
4 Correct 67 ms 29104 KB Output is correct
5 Correct 62 ms 29132 KB Output is correct
6 Correct 51 ms 28012 KB Output is correct
7 Correct 54 ms 28012 KB Output is correct
8 Correct 60 ms 28800 KB Output is correct
9 Correct 43 ms 26932 KB Output is correct
10 Correct 58 ms 28744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 15 ms 23832 KB Output is correct
7 Correct 14 ms 23848 KB Output is correct
8 Correct 13 ms 23824 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 14 ms 23832 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 14 ms 24076 KB Output is correct
13 Correct 17 ms 24020 KB Output is correct
14 Correct 18 ms 24148 KB Output is correct
15 Correct 15 ms 24076 KB Output is correct
16 Correct 14 ms 24088 KB Output is correct
17 Correct 15 ms 24084 KB Output is correct
18 Correct 15 ms 24020 KB Output is correct
19 Correct 147 ms 37904 KB Output is correct
20 Correct 149 ms 37896 KB Output is correct
21 Correct 126 ms 36060 KB Output is correct
22 Correct 130 ms 36068 KB Output is correct
23 Correct 132 ms 36004 KB Output is correct
24 Correct 118 ms 35028 KB Output is correct
25 Correct 122 ms 35036 KB Output is correct
26 Correct 127 ms 35856 KB Output is correct
27 Correct 132 ms 35940 KB Output is correct
28 Correct 134 ms 36152 KB Output is correct
29 Correct 146 ms 37128 KB Output is correct
30 Correct 146 ms 37200 KB Output is correct
31 Correct 139 ms 37068 KB Output is correct
32 Correct 140 ms 37140 KB Output is correct
33 Correct 138 ms 37160 KB Output is correct
34 Correct 113 ms 34744 KB Output is correct
35 Correct 116 ms 34648 KB Output is correct
36 Correct 109 ms 34432 KB Output is correct
37 Correct 129 ms 34528 KB Output is correct
38 Correct 114 ms 34812 KB Output is correct
39 Correct 128 ms 35612 KB Output is correct
40 Correct 109 ms 34164 KB Output is correct
41 Correct 121 ms 35116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 15 ms 23832 KB Output is correct
7 Correct 14 ms 23848 KB Output is correct
8 Correct 13 ms 23824 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 14 ms 23832 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 14 ms 24076 KB Output is correct
13 Correct 17 ms 24020 KB Output is correct
14 Correct 18 ms 24148 KB Output is correct
15 Correct 15 ms 24076 KB Output is correct
16 Correct 14 ms 24088 KB Output is correct
17 Correct 15 ms 24084 KB Output is correct
18 Correct 15 ms 24020 KB Output is correct
19 Correct 929 ms 95148 KB Output is correct
20 Correct 916 ms 96168 KB Output is correct
21 Correct 900 ms 96124 KB Output is correct
22 Correct 912 ms 96312 KB Output is correct
23 Correct 832 ms 92268 KB Output is correct
24 Correct 67 ms 29484 KB Output is correct
25 Correct 61 ms 28748 KB Output is correct
26 Correct 62 ms 28920 KB Output is correct
27 Correct 67 ms 29104 KB Output is correct
28 Correct 62 ms 29132 KB Output is correct
29 Correct 51 ms 28012 KB Output is correct
30 Correct 54 ms 28012 KB Output is correct
31 Correct 60 ms 28800 KB Output is correct
32 Correct 43 ms 26932 KB Output is correct
33 Correct 58 ms 28744 KB Output is correct
34 Correct 147 ms 37904 KB Output is correct
35 Correct 149 ms 37896 KB Output is correct
36 Correct 126 ms 36060 KB Output is correct
37 Correct 130 ms 36068 KB Output is correct
38 Correct 132 ms 36004 KB Output is correct
39 Correct 118 ms 35028 KB Output is correct
40 Correct 122 ms 35036 KB Output is correct
41 Correct 127 ms 35856 KB Output is correct
42 Correct 132 ms 35940 KB Output is correct
43 Correct 134 ms 36152 KB Output is correct
44 Correct 146 ms 37128 KB Output is correct
45 Correct 146 ms 37200 KB Output is correct
46 Correct 139 ms 37068 KB Output is correct
47 Correct 140 ms 37140 KB Output is correct
48 Correct 138 ms 37160 KB Output is correct
49 Correct 113 ms 34744 KB Output is correct
50 Correct 116 ms 34648 KB Output is correct
51 Correct 109 ms 34432 KB Output is correct
52 Correct 129 ms 34528 KB Output is correct
53 Correct 114 ms 34812 KB Output is correct
54 Correct 128 ms 35612 KB Output is correct
55 Correct 109 ms 34164 KB Output is correct
56 Correct 121 ms 35116 KB Output is correct
57 Correct 898 ms 95076 KB Output is correct
58 Correct 911 ms 95180 KB Output is correct
59 Correct 827 ms 91156 KB Output is correct
60 Correct 815 ms 90912 KB Output is correct
61 Correct 817 ms 90904 KB Output is correct
62 Correct 821 ms 91036 KB Output is correct
63 Correct 579 ms 79340 KB Output is correct
64 Correct 572 ms 79512 KB Output is correct
65 Correct 759 ms 86588 KB Output is correct
66 Correct 770 ms 86540 KB Output is correct
67 Correct 768 ms 87108 KB Output is correct
68 Correct 843 ms 91308 KB Output is correct
69 Correct 830 ms 91336 KB Output is correct
70 Correct 864 ms 90444 KB Output is correct
71 Correct 823 ms 90508 KB Output is correct
72 Correct 836 ms 90548 KB Output is correct
73 Correct 555 ms 77516 KB Output is correct
74 Correct 592 ms 78352 KB Output is correct
75 Correct 554 ms 77388 KB Output is correct
76 Correct 540 ms 77412 KB Output is correct
77 Correct 535 ms 77392 KB Output is correct
78 Correct 726 ms 84696 KB Output is correct
79 Correct 586 ms 74364 KB Output is correct
80 Correct 709 ms 81084 KB Output is correct