답안 #435787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435787 2021-06-23T17:57:11 Z stoyan_malinin Fountain (eJOI20_fountain) C++14
0 / 100
81 ms 18352 KB
#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 2e5 + 5;

struct SmartStack
{
    vector <pair <int, int>> v;
    vector <int> prefSum;

    int getSum(int ind)
    {
        if(ind==0) return prefSum.back();
        return prefSum.back() - prefSum[ind-1];
    }

    int push(pair <int, int> x)
    {
        v.push_back(x);
        
        if(prefSum.empty()==true) prefSum.push_back(x.second);
        else 
        {
            int sum = prefSum.back() + x.second;
            prefSum.push_back(sum);
        }
    }

    void pop()
    {
        v.pop_back();
        prefSum.pop_back();
    }

    pair <int, int> top()
    {
        return v.back();
    }

    bool isEmpty()
    {
        return v.empty();
    }
};

struct Query
{
    int qInd, v;

    Query(){}
    Query(int qInd, int v)
    {
        this->qInd = qInd;
        this->v = v;
    }
};

int n;
int d[MAXN], c[MAXN];
vector <Query> queries[MAXN];

int ans[MAXN];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int Q;
    cin >> n >> Q;
    for(int i = 0;i<n;i++) cin >> d[i] >> c[i];

    for(int q = 0;q<Q;q++)
    {
        int r, v;
        cin >> r >> v;
        
        r--;
        queries[r].emplace_back(q, v);
    }

    SmartStack st;
    for(int i = n-1;i>=0;i--)
    {
        while(st.isEmpty()==false && d[st.top().first]<=d[i]) st.pop();
        st.push({i, c[i]});

        for(Query &q: queries[i])
        {
            int v = q.v;
            int currAns = 0;
            
            for(int ind = st.v.size()-1;ind>=0;ind--)
            {
                v -= st.v[ind].second;
                if(v<=0) 
                {
                    currAns = st.v[ind].first + 1;
                    break;
                }
            }

            ans[q.qInd] = currAns;
        }
    }

    for(int q = 0;q<Q;q++) cout << ans[q] << '\n';
}
/*
6 5
4 10
6 8
3 5
4 14
10 9
4 20 
1 25
6 30
5 8
3 13
2 8
*/

Compilation message

fountain.cpp: In member function 'int SmartStack::push(std::pair<int, int>)':
fountain.cpp:29:5: warning: no return statement in function returning non-void [-Wreturn-type]
   29 |     }
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 10080 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 81 ms 18352 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 10080 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -