제출 #1284628

#제출 시각아이디문제언어결과실행 시간메모리
1284628Faisal_SaqibBitaro’s Party (JOI18_bitaro)C++20
100 / 100
617 ms119076 KiB
/* 
    VENI VIDI VICI
*/

// #pragma GCC optimize("Ofast","unroll-all-loops","fast-math","no-stack-protector","give-no-fuck")
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <algorithm>
// #include <set>
// #include <map>

using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

#define rep(i,x, n) for (int i = (x); i < (n); ++i)
#define repr(i,x, n) for (int i = (n) - 1; i >= (x); --i)
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());  
// #define sum accumulate

//using i128 = __int128;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
using sll = set<ll>;

template<class T>
istream& operator>>(istream& is, vector<T>& v) {
    for(auto &i:v) is>>i;
    return is;
}
template<class T1,class T2>
istream& operator>>(istream& is, pair<T1,T2>& p) {
    is>>p.fi>>p.se;
    return is;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(const auto &i:v) os<<i<<' ';
    return os;
}
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p) {
    os<<p.fi<<' '<<p.se; return os;
}
void pyn(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
void pYN(bool x)
{
    cout<<(x?"Yes":"No")<<endl;
}
void pAB(bool x)
{
    cout<<(x?"Alice":"Bob")<<endl;
}
ll powmod(ll a,ll b,ll modulo)
{
  if(b==0){
    return 1;
  }
  ll temp=powmod(a,b/2,modulo);
  if(b%2==0){
    return (temp*temp)%modulo;
  }
  else{
    return (a*((temp*temp)%modulo))%modulo;
  }
}
bool Prime(ll n){
    for (ll i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;
    return (n>1);
}
void readIO() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void solve();

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    // readIO();

    int uwu=1;

    // cin>>uwu;

    for(int tc=1;tc<=uwu;tc++) {
        // cout<<"Case #"<<tc<<": ";
        solve();
    }
    return 0;
}
const int N=1e5+100,B=100;
vl ma[N],rma[N];
ll dp[N];
bool vis[N],qry[N];
vector<pair<int,int>> cur[N],temp;
void solve()
{
    ll n,m,q;
    cin>>n>>m>>q;
    for(int i=0;i<m;i++)
    {
        int s,e;
        cin>>s>>e;
        ma[s].pb(e);
        rma[e].pb(s);
    }
    for(int i=1;i<=n;i++)
    {
        cur[i].push_back({0,i});
        
        for(auto p:rma[i]) // O(m)
        {

            temp.clear();
            int l1=0,l2=0;
            // sll nodes;
            while(l1<cur[i].size() and l2<cur[p].size() and temp.size()<B)
            {
                // if(nodes.find(cur[i][l1].second)!=nodes.end())
                if(vis[cur[i][l1].second])
                {
                    l1++;
                    continue;
                }
                // if(nodes.find(cur[p][l2].second)!=nodes.end())
                if(vis[cur[p][l2].second])
                {
                    l2++;
                    continue;
                }
                if(cur[i][l1].first>=(cur[p][l2].first+1))
                {
                    // nodes.insert(cur[i][l1].second);
                    vis[cur[i][l1].second]=1;
                    temp.push_back(cur[i][l1]);
                    l1++;
                }
                else
                {
                    // nodes.insert(cur[p][l2].second);
                    vis[cur[p][l2].second]=1;
                    temp.push_back({cur[p][l2].first+1,cur[p][l2].second});
                    l2++;                    
                }
            }

            while(l1<cur[i].size() and temp.size()<B)
            {
                // if(nodes.find(cur[i][l1].second)!=nodes.end())
                if(vis[cur[i][l1].second])
                {
                    l1++;
                    continue;
                }
                // nodes.insert(cur[i][l1].second);
                vis[cur[i][l1].second]=1;
                temp.push_back(cur[i][l1]);
                l1++;
            }
            
            while(l2<cur[p].size() and temp.size()<B)
            {
                // if(nodes.find(cur[p][l2].second)!=nodes.end())
                if(vis[cur[p][l2].second])
                {
                    l2++;
                    continue;
                }
                // nodes.insert(cur[p][l2].second);
                vis[cur[p][l2].second]=1;
                temp.push_back({cur[p][l2].first+1,cur[p][l2].second});
                l2++;
            }
            swap(cur[i],temp);
            for(auto j:cur[i])
            {
                vis[j.second]=0;
            }
        }
    }
    //O(n*b*lgB) 
    while(q--)//O(n)
    {
        int t,sz;
        cin>>t>>sz;
        // sll bk;
        vl bk;
        for(int i=0;i<sz;i++)
        {
            ll x;
            cin>>x;
            qry[x]=1;
            bk.pb(x);
        }
        if(sz<B)
        {
            ll ans=-1;
            for(auto x:cur[t])
            {
                // cout<<x.first<<' '<<x.second<<endl;
                if(!qry[x.second])
                {
                    ans=max(ans,(ll)x.first);
                }
            }
            cout<<ans<<endl;
        }
        else
        {
            for(int i=1;i<=n;i++)
            {
                dp[i]=-1;
            }
            dp[t]=0;
            for(int i=t;i>=1;i--)
            {
                if(dp[i]==-1)continue;
                // we want to update only from vertex reachiabl by t
                for(auto y:rma[i])
                {
                    dp[y]=max(dp[y],dp[i]+1);
                }
            }
            ll mx=-1;
            for(int i=1;i<=t;i++)
            {
                if(!qry[i]) // n lgn
                {
                    mx=max(mx,dp[i]);
                }   
            }
            cout<<mx<<endl;
        }
        for(auto x:bk)
            qry[x]=0;
    }

}

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'void readIO()':
bitaro.cpp:90:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:91:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...