Submission #864006

# Submission time Handle Problem Language Result Execution time Memory
864006 2023-10-21T16:40:42 Z FIFI_cpp Fountain (eJOI20_fountain) C++17
30 / 100
1500 ms 3240 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <iomanip>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
struct DATA
{
    int d;
    int c;
    int next;
};
DATA reservoir[100000];
int n,q;

int recur(int node,int quantity)
{
    while (node != -1 && quantity > reservoir[node].c)
    {
        quantity -= reservoir[node].c;
        node = reservoir[node].next;
    }
    if (node == -1)
        return 0;
    return node + 1;
}

int main() {
    fast
    cin >> n >> q;
    stack<pair<int,int>> sz;
    sz.push({1000000000,0});
    for (int i = 0;i < n;i++)
    {
        DATA inter;
        int d,c;
        cin >> d >> c;
        inter.d = d;
        inter.c = c;
        inter.next = -1;
        reservoir[i] = inter;
        while (inter.d > sz.top().first)
        {
            reservoir[sz.top().second].next = i;
            sz.pop();
        }
        sz.push({inter.d,i});
    }
    for (int i = 0;i < q;i++)
    {
        int r,v;
        cin >> r >> v;
        cout << recur(r - 1,v) << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1531 ms 3240 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Execution timed out 1531 ms 3240 KB Time limit exceeded
9 Halted 0 ms 0 KB -