Submission #128822

#TimeUsernameProblemLanguageResultExecution timeMemory
128822BTheroBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1303 ms181472 KiB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define pb push_back
#define mp make_pair
 
#define all(x) (x).begin(), (x).end()
 
#define fi first
#define se second
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;   
typedef pair<int, int> pii;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
const int MAXN = (int)1e5 + 5;
const int INF = (int)1e9;
const int K = 200;
 
pair<int, vector<int> > req[MAXN];
 
vector<int> adj[MAXN], par[MAXN];
 
int ban[MAXN], d[MAXN];
 
pii best[MAXN][K + 5];
 
int n, m, q;
 
void solve() {
    scanf("%d %d %d", &n, &m, &q);
 
    for (int i = 1; i <= m; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        adj[u].pb(v);
        par[v].pb(u);
    }
 
    for (int i = 1; i <= q; ++i) {
        int v, sz;
        scanf("%d %d", &v, &sz);
        vector<int> tmp(sz);
 
        for (int j = 0; j < sz; ++j) {
            scanf("%d", &tmp[j]);
        }
 
        req[i] = mp(v, tmp);
    }
 
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= K; ++j) {
            best[i][j] = mp(-INF, 0);
        }
    }
 
    for (int i = 1; i <= n; ++i) {
        best[i][0] = mp(-1, i);
        vector<pii> V(2 * K + 5);
 
        for (int j : par[i]) {
            int a = 0, b = 0, ptr = 0;
 
            while (a <= K || b <= K) {                 
                if (a > K) {
                    V[ptr++] = best[j][b++];
                }
                else if (b > K) {
                    V[ptr++] = best[i][a++];
                }
                else {
                    if (best[i][a] > best[j][b]) {
                        V[ptr++] = best[i][a++];
                    }
                    else {
                        V[ptr++] = best[j][b++];
                    }
                }
            }

            int ptr2 = 0;

            for (int k = 0; k <= ptr; ++k) {
                if (!ban[V[k].se] && ptr2 <= K) {
                    best[i][ptr2++] = V[k]; 
                    ban[V[k].se] = 1;
                }
            }
 
            for (int k = 0; k <= ptr; ++k) {
                ban[V[k].se] = 0;
            }
        }
 
        for (int j = 0; j <= K; ++j) {
            ++best[i][j].fi;
        }
    }
 
    for (int i = 1; i <= q; ++i) {
        int v = req[i].fi, ans = -1;
        vector<int> V = req[i].se;
 
        for (int x : V) {
            ban[x] = 1;
        }
 
        if (V.size() >= K) {
            fill(d + 1, d + n + 1, -INF);
            d[v] = 0;
 
            for (int j = v - 1; j > 0; --j) {
                for (int p : adj[j]) {
                    d[j] = max(d[j], d[p] + 1);
                }
            }
 
            for (int j = 1; j <= v; ++j) {
                if (!ban[j]) {
                    ans = max(ans, d[j]);
                }
            } 
        }
        else {
            for (int j = 0; j <= K; ++j) {
                if (!ban[best[v][j].se]) {
                    ans = max(ans, best[v][j].fi);
                }
            }
        }
 
        printf("%d\n", ans);
 
        for (int x : V) {
            ban[x] = 0;
        }
    }
}
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

Compilation message (stderr)

bitaro.cpp: In function 'void solve()':
bitaro.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &v, &sz);
         ~~~~~^~~~~~~~~~~~~~~~~~
bitaro.cpp:56:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &tmp[j]);
             ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...