제출 #571237

#제출 시각아이디문제언어결과실행 시간메모리
571237YouAreMyGalaxyHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1335 ms96168 KiB
//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();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...