Submission #615522

# Submission time Handle Problem Language Result Execution time Memory
615522 2022-07-31T10:10:08 Z ArsBud Fountain (eJOI20_fountain) C++14
0 / 100
1500 ms 2888 KB
#include <iostream>

using namespace std;

int N, Q, k, y = 0, n, v, vid, r, g;
int m[200005], i[100005], t[100005];

void F(int x)
{
    if(i[y] < i[x])
    {
        m[y] = x;
        return;
    }
    if(m[y] > 0 || m[x] <= 0)
    {
        if(x == N)
        {
            m[y] = -1;
        }
        return;
    }
    F(m[x]);
}

void F1(int w)
{
    if(t[w] >= v)
    {
        v = 0;
        n = w;
        return;
    }
    if(v > t[w] && m[w] == -1)
    {
        n = -1;
        return;
    }
    v -= t[w];
    F1(m[w]);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> N >> Q;
    r = (1 + N) / 2;
    for(int a = 1; a <= N; a++)
    {
        cin >> i[a] >> t[a];
        if(i[a] > i[a - 1])
        {
            g++;
        }
    }
    if(g == N)
    {
        t[0] = 0;
        for(int a = 1; a <= N; a++)
        {
            t[a] = t[a - 1];
        }
        for(int a = 0; a < Q; a++)
        {
            cin >> n >> v;
            int lo = 1, hi = N, mid;
            while(lo < hi)
            {
                mid = (lo + hi + 1) / 2;
                if(t[mid] < v)
                {
                    hi = mid;
                }
                if(t[mid] > v)
                {
                    lo = mid;
                }
                else
                {
                    break;
                }
            }
            cout << lo;
        }
    }
    m[N] = -1;
    for(int a = N; a >= 1; a--)
    {
        if(i[a] < i[a + 1])
        {
            m[a] = a + 1;
        }
        else
        {
            y = a;
            F(a + 1);
            if(m[a] == 0)
            {
                m[a] = N - 1;
            }
        }
    }
    for(int a = 0; a < Q; a++)
    {
        cin >> n >> v;
        n;
        F1(n);
        if(v < 0)
        {
            cout << 0 << '\n';
        }
        else
        {
            cout << max(n, 0) << '\n';
        }
    }
    return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:108:9: warning: statement has no effect [-Wunused-value]
  108 |         n;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Execution timed out 1588 ms 340 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1588 ms 2888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Execution timed out 1588 ms 340 KB Time limit exceeded
6 Halted 0 ms 0 KB -