This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(x) (int)(x.size())
#define pb push_back
const int MX = 450005,L=30;
vector<pair<int,int> > vec[150005];
int up[MX][L],curr[150005];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
for (int i = 0; i < M; ++i)
{
vec[R[i][0]].pb({R[i][1],i});
vec[R[i][1]].pb({R[i][0],M+i});
}
for (int i = 0; i < N; ++i)
{
multiset<pair<int,int> > myset;
for (int j = 0; j < sz(vec[i]); ++j)
{
int val=vec[i][j].se-((vec[i][j].se>=M)?M:0);
myset.insert({val,j});
}
for (int j = 0; j < sz(vec[i]); ++j)
{
int val=vec[i][j].se-((vec[i][j].se>=M)?M:0);
int c=val+((vec[i][j].se>=M)?0:M);
myset.erase(myset.find({val,j}));
if(!sz(myset))up[c][0]=vec[i][j].se;
else up[c][0]=vec[i][myset.begin()->se].se;
myset.insert({val,j});
}
up[i+2*M][0]=vec[i][myset.begin()->se].se;
}
for (int i = 1; i < L; ++i)
for (int j = 0; j < 2*M+N; ++j)
up[j][i]=up[up[j][i-1]][i-1];
for (int i = 0; i < Q; ++i)
{
int ans=0;
for (int j = 0; j < N; ++j)
curr[j]=2*M+j;
for (int j = 0; j < L; ++j)
{
if(!((G[i]>>j)&1))continue;
for (int z = 0; z < N; ++z)
curr[z]=up[curr[z]][j];
}
for (int j = 0; j < N; ++j)
ans+=(((curr[j]>=M)?R[curr[j]-M][0]:R[curr[j]][1])==P);
answer(ans);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |