Submission #168989

# Submission time Handle Problem Language Result Execution time Memory
168989 2019-12-17T11:20:44 Z SamAnd Red-blue table (IZhO19_stones) C++17
0 / 100
30 ms 23928 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 1000006, INF = 1000000009;

int ka()
{
    int x = 0;
    while (1)
    {
        char y = getchar();
        if ('0' <= y && y <= '9')
            x = (x * 10) + (y - '0');
        else
            return x;
    }
}

int n, qq;
int a[N];

vector<pair<pair<int, int>, int> > v[N];

int t[N * 4];
int laz[N * 4];

void shi(int pos)
{
    if (laz[pos] == 0)
        return;
    t[pos * 2] = max(t[pos * 2], laz[pos]);
    laz[pos * 2] = max(laz[pos * 2], laz[pos]);
    t[pos * 2 + 1] = max(t[pos * 2 + 1], laz[pos]);
    laz[pos * 2 + 1] = max(laz[pos * 2 + 1], laz[pos]);
    laz[pos] = 0;
}

void ubd(int tl, int tr, int l, int r, int y, int pos)
{
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        t[pos] = max(t[pos], y);
        laz[pos] = max(laz[pos], y);
        return;
    }
    shi(pos);
    int m = (tl + tr) / 2;
    ubd(tl, m, l, min(m, r), y, pos * 2);
    ubd(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1);
    t[pos] = max(t[pos * 2], t[pos * 2 + 1]);
}

int qry(int tl, int tr, int l, int r, int pos)
{
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[pos];
    shi(pos);
    int m = (tl + tr) / 2;
    return max(qry(tl, m, l, min(m, r), pos * 2),
               qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}

char ans[N];
int main()
{
    //freopen("input.txt", "r", stdin);
    n = ka();
    qq = ka();
    for (int i = 1; i <= n; ++i)
        a[i] = ka();
    for (int i = 1; i <= qq; ++i)
    {
        int l, r, k;
        l = ka();
        r = ka();
        k = ka();
        v[r].push_back(m_p(m_p(l, k), i));
    }
    stack<int> s;
    for (int i = 1; i <= n; ++i)
    {
        while (!s.empty() && a[i] >= a[s.top()])
            s.pop();
        if (!s.empty())
        {
            ubd(1, n, 1, s.top(), a[i] + a[s.top()], 1);
        }
        s.push(i);
        for (int j = 0; j < v[i].size(); ++j)
        {
            if (qry(1, n, v[i][j].first.first, i, 1) <= v[i][j].first.second)
                ans[v[i][j].second] = '1';
            else
                ans[v[i][j].second] = '0';
        }
    }
    for (int i = 1; i <= qq; ++i)
    {
        putchar(ans[i]);
        putchar('\n');
    }
    return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:93:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v[i].size(); ++j)
                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 23928 KB Wrong answer
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -