Submission #146256

# Submission time Handle Problem Language Result Execution time Memory
146256 2019-08-23T06:39:46 Z Yersh Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
94 ms 5852 KB
#include<bits/stdc++.h>
#define NFS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define fr first
#define se second
#define th third
#define pb(v) push_back(v)
#define mk(x, y) make_pair(x, y)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
const ll mod = 1e9 + 7;
string en = "\n";
ll a[N], d[N];
pair <int, int> t[N * 4], ans;

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        t[v].fr = a[tl];
        return;
    }
    int tm = (tl + tr) / 2;
    build (v * 2, tl, tm);
    build (v * 2 + 1, tm + 1, tr);
    t[v].fr = t[v * 2].fr;
    t[v].se = max(t[v * 2].se, t[v * 2 + 1].fr);
    if (t[v * 2 + 1].fr >= t[v].fr)
    {
        t[v].se = t[v * 2].se;
    }
}

void get(int u, int tl, int tr, int l, int r)
{
    if (l > tr || r < tl)
    {
        return;
    }
    if (tl >= l && tr <= r)
    {
        if (t[u].fr > ans.fr)
        {
            ans.fr = t[u].fr;
            ans.se = t[u].se;
        }
        else if (t[u].se > ans.se)
        {
            ans.se = t[u].se;
        }
        return;
    }
    int tm = (tl + tr) / 2;
    get(u * 2, tl, tm, l, r);
    get(u * 2 + 1, tm + 1, tr, l, r);
}

int main()
{
    NFS;
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i];
    }
    build(1, 1, n);
    for (int i = 1; i <= m; i ++)
    {
        int l, r, k;
        cin >> l >> r >> k;
        get(1, 1, n, l, r);
        if (ans.fr + ans.se > k)
        {
            cout << 0 << en;
            continue;
        }
        cout << 1 << en;
        ans.fr = 0;
        ans.se = 0;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 5852 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 5412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -