답안 #498074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498074 2021-12-24T11:25:41 Z Karabasan Fountain (eJOI20_fountain) C++17
0 / 100
92 ms 15188 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"
#define int long long
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()
{
    cin>>n>>q;
    for(int i=1;i<=n;i++)
        cin>>d[i]>>c[i];
    for(int i=1;i<=q;i++)
    {
        int a,b;
        cin>>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(auto i:ind)
            cout<<i<<" ";
        cout<<endl;
        for(auto i:v)
            cout<<i<<" ";
        cout<<endl;
        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++)
        cout<<cevap[i]<<endl;
}
signed main()
{
    fast1
    //freopen ("lca.gir","r",stdin);
    //freopen ("lca.cik","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Compilation message

fountain.cpp: In function 'void solve()':
fountain.cpp:66:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for(int i=1;i<ind.size();i++)
      |                     ~^~~~~~~~~~~
fountain.cpp:68:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             for(int j=0;j<p[ind[i]].size();j++)
      |                         ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 92 ms 15188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -