Submission #572072

#TimeUsernameProblemLanguageResultExecution timeMemory
572072HanksburgerHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
64 / 100
143 ms20312 KiB
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > v[200005];
vector<pair<int, int> > w;
int a[200005], b[200005];
bool c[200005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    for (int i=1; i<=n; i++)
        cin >> a[i];
    for (int i=1; i<=q; i++)
    {
        int l, r, x;
        cin >> l >> r >> x;
        v[r].push_back({{l, x}, i});
    }
    for (int i=1; i<=n; i++)
    {
//        cout << "i=" << i << '\n';
        while (w.size() && w[w.size()-1].first<=a[i])
            w.pop_back();
        if (w.size())
        {
            int x=w[w.size()-1].first+a[i];
//            cout << "update " << w[w.size()-1].second << ' ' << x << '\n';
            for (int i=w[w.size()-1].second; i; i-=(i&-i))
                b[i]=max(b[i], x);
        }
        w.push_back({a[i], i});
//        cout << "w: ";
//        for (pair<int, int> x:w)
//            cout << x.first << ' ';
//        cout << '\n';
        for (int j=0; j<v[i].size(); j++)
        {
            int mx=0;
            for (int k=v[i][j].first.first; k<=n; k+=(k&-k))
                mx=max(mx, b[k]);
            c[v[i][j].second]=(mx<=v[i][j].first.second);
        }
    }
    for (int i=1; i<=q; i++)
        cout << c[i] << '\n';
    return 0;
}

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:39:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int j=0; j<v[i].size(); j++)
      |                       ~^~~~~~~~~~~~
#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...