Submission #498082

# Submission time Handle Problem Language Result Execution time Memory
498082 2021-12-24T11:30:01 Z Karabasan Fountain (eJOI20_fountain) C++17
60 / 100
1500 ms 10080 KB
#include <bits/stdc++.h>
#define ll long long
#define fast1 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,avx")
#pragma GCC optimize("unroll-loops")

int n,m,k,q;
int d[100005];
int c[100005];
int pre[100005];
vector<pair<int,int> > p[200005];
int mark[100005];
int nextt[100005];
int cevap[200005];
void solve()
{
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&d[i],&c[i]);
    for(int i=1;i<=q;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        p[a].push_back({b,i});
    }
    stack<int> st;
    st.push(1);
    for(int i=2;i<=n;i++)
    {
        while(!st.empty()&&d[st.top()]<d[i])
        {
            nextt[st.top()]=i;
            st.pop();
        }
        st.push(i);
    }
    for(int u=1;u<=n;u++)
    {
        vector<int> v;
        vector<int> ind;
        if(mark[u])
            continue;
        mark[u]=1;
        v.push_back(0);
        v.push_back(c[u]);
        ind.push_back(0);
        ind.push_back(u);
        int g=nextt[u];
        while(g!=0)
        {
            mark[g]=1;
            ind.push_back(g);
            v.push_back(v[v.size()-1]+c[g]);
            g=nextt[g];
        }
        for(int i=1;i<ind.size();i++)
        {
            for(int j=0;j<p[ind[i]].size();j++)
            {
                int a=ind[lower_bound(v.begin()+i,v.end(),p[ind[i]][j].first+v[i-1])-v.begin()];
                if(a<=n)
                    cevap[p[ind[i]][j].second]=a;
                else cevap[p[ind[i]][j].second]=0;
            }
        }
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",cevap[i]);
}
int main()
{
    //fast1
    int t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Compilation message

fountain.cpp: In function 'void solve()':
fountain.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int i=1;i<ind.size();i++)
      |                     ~^~~~~~~~~~~
fountain.cpp:61:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             for(int j=0;j<p[ind[i]].size();j++)
      |                         ~^~~~~~~~~~~~~~~~~
fountain.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
fountain.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d%d",&d[i],&c[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
fountain.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 6 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 9856 KB Output is correct
2 Correct 88 ms 10080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 6 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 78 ms 9856 KB Output is correct
9 Correct 88 ms 10080 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Execution timed out 1596 ms 7888 KB Time limit exceeded
12 Halted 0 ms 0 KB -