제출 #345166

#제출 시각아이디문제언어결과실행 시간메모리
345166casperwang열대 식물원 (Tropical Garden) (IOI11_garden)C++14
0 / 100
1 ms748 KiB
#include "garden.h" #include "gardenlib.h" #include <bits/stdc++.h> #define All(x) x.begin(), x.end() #define pb emplace_back #define pii pair<int,int> #define ff first #define ss second using namespace std; #define debug(args...) kout("[ " + string(#args) + " ]", args) void kout() { cerr << endl; } template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); } template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; } const int MAXN = 150000; const int MAXQ = 2000; const int L = 30; void count_routes(int N, int M, int P, int R[MAXN][2], int Q, int G[MAXQ]) { vector <vector<int>> path(N), p(2*N); for (int i = 0; i < M; i++) { path[R[i][0]].pb(R[i][1]); path[R[i][1]].pb(R[i][0]); } vector <vector<int>> anc(2*N); for (int i = 0; i < N; i++) { anc[i].resize(L); anc[i+N].resize(L); int t = path[i][0]; anc[i][0] = (path[t][0] == i && path[t].size() > 1) ? t+N : t; p[anc[i][0]].pb(i); if (path[i].size() > 1) { t = path[i][1]; anc[i+N][0] = (path[t][0] == i && path[t].size() > 1) ? t+N : t; p[anc[i+N][0]].pb(i+N); } else anc[i+N][0] = i+N; } vector <int> vis1(2*N), vis2(2*N); queue <int> nxt; nxt.push(P); vis1[P] = 0; while (nxt.size()) { int now = nxt.front(); nxt.pop(); for (int i : p[now]) { if (!vis1[i]) { vis1[i] = vis1[now] + 1; nxt.push(i); } } } nxt.push(P+N); vis2[P+N] = 0; while (nxt.size()) { int now = nxt.front(); nxt.pop(); for (int i : p[now]) { if (!vis2[i]) { vis2[i] = vis2[now] + 1; nxt.push(i); } } } for (int i = 1; i < L; i++) for (int j = 0; j < 2*N; j++) anc[j][i] = anc[anc[j][i-1]][i-1]; for (int q = 0; q < Q; q++) { int ans = 0; for (int i = 0; i < N; i++) { if (vis1[P] && (G[q] - vis1[i]) % vis1[P] == 0) ans++; else if (vis2[P+N] && (G[q] - vis2[i]) % vis2[P+N] == 0) ans++; else if (vis1[N+P]+vis2[P] && (G[q] - vis1[i]) % (vis2[P]+vis1[N+P]) == vis2[P]) ans++; else if (vis1[N+P]+vis2[P] && (G[q] - vis2[i]) % (vis2[P]+vis1[N+P]) == vis1[N+P]) ans++; } answer(ans); } return; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...