Submission #70123

#TimeUsernameProblemLanguageResultExecution timeMemory
70123WA_TLETropical Garden (IOI11_garden)C++14
69 / 100
5034 ms38788 KiB
#include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> #include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #include<bitset> #include<stack> #include<memory> using namespace std; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /* cout<<setprecision(20); cin.tie(0); ios::sync_with_stdio(false); */ const llint mod=1000000000; const llint big=2.19e15+1; const long double pai=3.141592653589793238462643383279502884197; const long double eps=1e-15; template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;} template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;} llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);} llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;} template<class T> void SO(T& ve){sort(ve.begin(),ve.end());} template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());} template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();} template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();} //O(mQlogGは通る!) //void answer(int X){cout<<X<<endl;} void answer(int X); void count_routes(int N,int M,int P,int R[][2],int Q,int G[]){ //まずはどのみちがどの道につながってますか static int dab[300000][30]; //噴水から歩き始めるものの候補を調べる int h,i,j; static int best[150000]; static bool seco[150000]={}; static bool ok[300000]={0}; for(i=0;i<N;i++){best[i]=-1;} for(i=0;i<M*2;i++){ int a=R[i/2][0]; int b=R[i/2][1]; if(i%2){swap(a,b);} if(best[a]==-1){best[a]=i;} else if(!seco[a]){seco[a]=1;dab[best[a]^1][0]=i;} if(best[b]!=-1&&best[b]!=(i^1)){dab[i][0]=best[b];} if(b==P){ok[i]=1;} } for(i=0;i<N;i++){ if(!seco[i]){dab[best[i]^1][0]=best[i];} } for(i=0;i<M*2;i++){ int a=R[i/2][0]; int b=R[i/2][1]; if(i%2){swap(a,b);} int nex=dab[i][0]; int c=R[nex/2][0]; int d=R[nex/2][1]; if(nex%2){swap(c,d);} //cout<<"a,b,nexa,nexb"<<a<<b<<c<<d<<endl; } for(h=1;h<30;h++){ for(i=0;i<M*2;i++){dab[i][h]=dab[dab[i][h-1]][h-1];} } for(j=0;j<Q;j++){ int K=G[j]-1; int ans=0; for(i=0;i<N;i++){ int bas=best[i]; for(h=0;h<30;h++){if(K&(1<<h)){bas=dab[bas][h];}} if(ok[bas]){ans++;} } //cerr<<endl; answer(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...