Submission #944973

# Submission time Handle Problem Language Result Execution time Memory
944973 2024-03-13T09:15:57 Z gelastropod Meetings (IOI18_meetings) C++14
0 / 100
13 ms 2004 KB
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
/*
struct node
{
    int s, e, m, v;
    node *l, *r;

    node (int _s, int _e) : s(_s), e(_e), m((_s + _e) / 2), v(-1)
    {
        if (s != e)
            l = new node(s, m),
            r = new node(m + 1, e);
    }

    void upd(int n, int x)
    {
        if (s == e)
        {
            v = x;
            return;
        }
        if (n <= m)
            l->upd(n, x);
        else
            r->upd(n, x);
        v = max(l->v, r->v);
    }

    int qry(int a, int b)
    {
        if (b < s || a > e)
            return -1;
        if (a <= s && b >= e)
            return v;
        return max(l->qry(a, b), r->qry(a, b));
    }
} *root;*/

vector<long long> minimum_costs(vector<signed> H, vector<signed> L,
                                vector<signed> R) {
    int N = H.size(), Q = L.size();
    stack<int> stk;
    vector<int> f2s(N, 0), b2s(N, 0);
    for (int i = 0; i < N; i++)
    {
        if (H[i] == 2)
        {
            f2s[i] = i;
            while (!stk.empty())
            {
                f2s[stk.top()] = i;
                stk.pop();
            }
        }
        else
        {
            stk.push(i);
        }
    }
    while (!stk.empty())
    {
        f2s[stk.top()] = -1;
        stk.pop();
    }
    for (int i = N - 1; i >= 0; i--)
    {
        if (H[i] == 2)
        {
            b2s[i] = i;
            while (!stk.empty())
            {
                b2s[stk.top()] = i;
                stk.pop();
            }
        }
        else
        {
            stk.push(i);
        }
    }
    while (!stk.empty())
    {
        b2s[stk.top()] = -1;
        stk.pop();
    }
    vector<int> ans;
    for (int i = 0; i < Q; i++)
    {
        if (f2s[L[i]] == -1)
            ans.push_back(R[i] + 1 - L[i]);
        else
            ans.push_back((R[i] + 1 - L[i]) * 2 - max(f2s[L[i]] - L[i], R[i] - b2s[R[i]]));
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 13 ms 2004 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 13 ms 2004 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -