#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
namespace Wrap
{
#define SZ 666666
int n,m,N,p,a[SZ],b[SZ],u[SZ];
int gb(int e,int t)
{return a[e]^b[e]^t;}
vector<int> e[SZ],pre[SZ];
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> pii;
struct Sup
{
vector<int> v[SZ];
int GA;
map<int,vector<int> > sb;
void init(int x)
{
queue<pii> q;
q.push(pii(x,0));
while(!q.empty())
{
pii w=q.front(); q.pop();
if(v[w.fi].size()>3) continue;
v[w.fi].pb(w.se);
for(auto g:pre[w.fi])
q.push(pii(g,w.se+1));
}
GA=-1;
for(int i=0;i<N;++i) if(v[i].size()&&i%2==0)
{
int G=(v[i].size()>=2)?(v[i][1]-v[i][0]):(1.01e9);
if(GA==-1) GA=G;
sb[v[i][0]%G].pb(v[i][0]/G);
}
for(auto&u:sb)
sort(u.se.begin(),u.se.end());
}
int qry(int x)
{
if(GA==-1) return 0;
auto&w=sb[x%GA];
return upper_bound(w.begin(),w.end(),x/GA)-w.begin();
}
}A,B;
}
void count_routes(int N_, int M, int P, int R[][2], int Q, int G[])
{
using namespace Wrap;
n=N_,m=M,p=P,N=n*2;
for(int i=0;i<m;++i)
a[i]=R[i][0],b[i]=R[i][1],
e[a[i]].pb(i),e[b[i]].pb(i);
for(int i=0;i<n;++i)
for(int j=0;j<2;++j)
{
int c=e[i].front();
if(j&&e[i].size()>1)
c=e[i][1];
int w=gb(c,i);
int d=(e[w].front()==c);
u[i*2+j]=w*2+d;
pre[w*2+d].pb(i*2+j);
}
A.init(P*2);
B.init(P*2+1);
for(int j=0;j<Q;++j)
answer(A.qry(G[j])+B.qry(G[j]));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
63324 KB |
Output is correct |
2 |
Correct |
60 ms |
63124 KB |
Output is correct |
3 |
Correct |
60 ms |
63228 KB |
Output is correct |
4 |
Correct |
59 ms |
62968 KB |
Output is correct |
5 |
Correct |
62 ms |
63060 KB |
Output is correct |
6 |
Correct |
56 ms |
63152 KB |
Output is correct |
7 |
Correct |
59 ms |
62944 KB |
Output is correct |
8 |
Correct |
64 ms |
63196 KB |
Output is correct |
9 |
Correct |
64 ms |
63308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
63324 KB |
Output is correct |
2 |
Correct |
60 ms |
63124 KB |
Output is correct |
3 |
Correct |
60 ms |
63228 KB |
Output is correct |
4 |
Correct |
59 ms |
62968 KB |
Output is correct |
5 |
Correct |
62 ms |
63060 KB |
Output is correct |
6 |
Correct |
56 ms |
63152 KB |
Output is correct |
7 |
Correct |
59 ms |
62944 KB |
Output is correct |
8 |
Correct |
64 ms |
63196 KB |
Output is correct |
9 |
Correct |
64 ms |
63308 KB |
Output is correct |
10 |
Correct |
57 ms |
62948 KB |
Output is correct |
11 |
Correct |
94 ms |
65544 KB |
Output is correct |
12 |
Correct |
93 ms |
66868 KB |
Output is correct |
13 |
Correct |
264 ms |
102356 KB |
Output is correct |
14 |
Correct |
289 ms |
76968 KB |
Output is correct |
15 |
Correct |
513 ms |
84884 KB |
Output is correct |
16 |
Correct |
389 ms |
78848 KB |
Output is correct |
17 |
Correct |
347 ms |
77120 KB |
Output is correct |
18 |
Correct |
106 ms |
66868 KB |
Output is correct |
19 |
Correct |
304 ms |
76808 KB |
Output is correct |
20 |
Correct |
524 ms |
84904 KB |
Output is correct |
21 |
Correct |
387 ms |
78680 KB |
Output is correct |
22 |
Correct |
334 ms |
76716 KB |
Output is correct |
23 |
Correct |
270 ms |
77512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
63324 KB |
Output is correct |
2 |
Correct |
60 ms |
63124 KB |
Output is correct |
3 |
Correct |
60 ms |
63228 KB |
Output is correct |
4 |
Correct |
59 ms |
62968 KB |
Output is correct |
5 |
Correct |
62 ms |
63060 KB |
Output is correct |
6 |
Correct |
56 ms |
63152 KB |
Output is correct |
7 |
Correct |
59 ms |
62944 KB |
Output is correct |
8 |
Correct |
64 ms |
63196 KB |
Output is correct |
9 |
Correct |
64 ms |
63308 KB |
Output is correct |
10 |
Correct |
57 ms |
62948 KB |
Output is correct |
11 |
Correct |
94 ms |
65544 KB |
Output is correct |
12 |
Correct |
93 ms |
66868 KB |
Output is correct |
13 |
Correct |
264 ms |
102356 KB |
Output is correct |
14 |
Correct |
289 ms |
76968 KB |
Output is correct |
15 |
Correct |
513 ms |
84884 KB |
Output is correct |
16 |
Correct |
389 ms |
78848 KB |
Output is correct |
17 |
Correct |
347 ms |
77120 KB |
Output is correct |
18 |
Correct |
106 ms |
66868 KB |
Output is correct |
19 |
Correct |
304 ms |
76808 KB |
Output is correct |
20 |
Correct |
524 ms |
84904 KB |
Output is correct |
21 |
Correct |
387 ms |
78680 KB |
Output is correct |
22 |
Correct |
334 ms |
76716 KB |
Output is correct |
23 |
Correct |
270 ms |
77512 KB |
Output is correct |
24 |
Correct |
60 ms |
63004 KB |
Output is correct |
25 |
Correct |
83 ms |
65596 KB |
Output is correct |
26 |
Correct |
103 ms |
66868 KB |
Output is correct |
27 |
Correct |
278 ms |
102644 KB |
Output is correct |
28 |
Correct |
310 ms |
76960 KB |
Output is correct |
29 |
Correct |
520 ms |
84924 KB |
Output is correct |
30 |
Correct |
403 ms |
79032 KB |
Output is correct |
31 |
Correct |
351 ms |
77072 KB |
Output is correct |
32 |
Correct |
109 ms |
67092 KB |
Output is correct |
33 |
Correct |
290 ms |
76996 KB |
Output is correct |
34 |
Correct |
520 ms |
84984 KB |
Output is correct |
35 |
Correct |
387 ms |
78900 KB |
Output is correct |
36 |
Correct |
377 ms |
78696 KB |
Output is correct |
37 |
Correct |
277 ms |
77484 KB |
Output is correct |
38 |
Correct |
364 ms |
106704 KB |
Output is correct |