#include "gardenlib.h"
#include "garden.h"
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define debug(...) cout << "Line: " << __LINE__ << endl; \
printDebug(", "#__VA_ARGS__, __VA_ARGS__)
template <typename T>
void printDebug(const char* name, T&& arg1) { cout << (name + 2) << " = " << arg1 << endl; }
template <typename T, typename... T2>
void printDebug(const char* names, T&& arg1, T2&&... args) {
const char* end = strchr(names + 1, ',');
cout.write(names + 2, end - names - 2) << " = " << arg1 << endl;
printDebug(end, args...);
}
const int MAX_N = 4e5 + 10;
vector<int> g[MAX_N];
vector<int> help[MAX_N];
int n, par[MAX_N], mn[MAX_N];
int cnt[2];
vector<int> ans[2][MAX_N];
int used[MAX_N];
int d[2][MAX_N];
void dfs(int x, int who) {
if(x < n) {
ans[who][d[who][x]].push_back(d[who][x]);
}
used[x] = true;
for(auto it : g[x]) {
if(used[it]) {cnt[who] = d[who][x] - d[who][it] + 1; continue;}
d[who][it] = d[who][x] + 1;
dfs(it, who);
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
n = N;
fill_n(mn, n, 1e8);
for(int i = 0; i < M; i ++) {
int a = R[i][0], b = R[i][1];
help[a].push_back(i);
help[b].push_back(i);
chkmin(mn[a], i);
chkmin(mn[b], i);
}
for(int i = 0; i < n; i ++) {
sort(help[i].begin(), help[i].end());
if(help[i].size() == 0) {
continue;
} else {
// ???
int best = help[i][0];
par[i] = R[best][0] + R[best][1] - i;
if(mn[par[i]] == best) {
par[i] += n;
}
best = help[i][1 % help[i].size()];
par[i + n] = R[best][0] + R[best][1] - i;
if(mn[par[i + n]] == best) {
par[i + n] += n;
}
}
}
for(int i = 0; i < 2 * n; i ++) {
g[par[i]].push_back(i);
}
cnt[0] = cnt[1] = -1;
fill_n(used, n, 0);
dfs(P, 0);
cout << endl;
fill_n(used, n, 0);
dfs(P + n, 1);
for(int i = 0; i < 2; i ++) {
if(cnt[i] == -1) {continue;}
for(int j = cnt[i]; j < MAX_N; j ++) {
for(auto it : ans[i][j]) {
ans[i][it % cnt[i]].push_back(it);
}
}
}
for(int i = 0; i < Q; i ++) {
int ret = 0;
if(cnt[0] != -1) {
ret += upper_bound(ans[0][G[i] % cnt[0]].begin(), ans[0][G[i] % cnt[0]].end(), G[i]) - ans[0][G[i] % cnt[0]].begin();
} else {
ret += ans[0][G[i]].size();
}
if(cnt[1] != -1) {
ret += upper_bound(ans[1][G[i] % cnt[1]].begin(), ans[1][G[i] % cnt[1]].end(), G[i]) - ans[1][G[i] % cnt[1]].begin();
} else {
ret += ans[1][G[i]].size();
}
answer(ret);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
38092 KB |
Output is correct |
2 |
Correct |
24 ms |
38092 KB |
Output is correct |
3 |
Correct |
25 ms |
38024 KB |
Output is correct |
4 |
Correct |
27 ms |
37940 KB |
Output is correct |
5 |
Correct |
24 ms |
37808 KB |
Output is correct |
6 |
Correct |
26 ms |
38272 KB |
Output is correct |
7 |
Correct |
24 ms |
37940 KB |
Output is correct |
8 |
Correct |
25 ms |
38048 KB |
Output is correct |
9 |
Correct |
26 ms |
38212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
38092 KB |
Output is correct |
2 |
Correct |
24 ms |
38092 KB |
Output is correct |
3 |
Correct |
25 ms |
38024 KB |
Output is correct |
4 |
Correct |
27 ms |
37940 KB |
Output is correct |
5 |
Correct |
24 ms |
37808 KB |
Output is correct |
6 |
Correct |
26 ms |
38272 KB |
Output is correct |
7 |
Correct |
24 ms |
37940 KB |
Output is correct |
8 |
Correct |
25 ms |
38048 KB |
Output is correct |
9 |
Correct |
26 ms |
38212 KB |
Output is correct |
10 |
Correct |
24 ms |
37904 KB |
Output is correct |
11 |
Correct |
36 ms |
40536 KB |
Output is correct |
12 |
Correct |
53 ms |
42444 KB |
Output is correct |
13 |
Incorrect |
81 ms |
65792 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
38092 KB |
Output is correct |
2 |
Correct |
24 ms |
38092 KB |
Output is correct |
3 |
Correct |
25 ms |
38024 KB |
Output is correct |
4 |
Correct |
27 ms |
37940 KB |
Output is correct |
5 |
Correct |
24 ms |
37808 KB |
Output is correct |
6 |
Correct |
26 ms |
38272 KB |
Output is correct |
7 |
Correct |
24 ms |
37940 KB |
Output is correct |
8 |
Correct |
25 ms |
38048 KB |
Output is correct |
9 |
Correct |
26 ms |
38212 KB |
Output is correct |
10 |
Correct |
24 ms |
37904 KB |
Output is correct |
11 |
Correct |
36 ms |
40536 KB |
Output is correct |
12 |
Correct |
53 ms |
42444 KB |
Output is correct |
13 |
Incorrect |
81 ms |
65792 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |