Re: [algogeeks] Re: SPOJ THRBL
im sorry .. y wrote: > yea.. now got ac.. :) mistake was k==y is also possible but x got WA .. thank u :) > > On Sat, Jun 11, 2011 at 2:39 PM, keyan karthi > wrote: > >> k=query(x,y-1) >> if(k==x) >> count++ >> with this change ur code ACs :) >> >> >> On Sat, Jun 11, 2011 at 1:24 PM, Radhika Renganathan < >> radi.coo...@gmail.com> wrote: >> >>> i did the same prob wit range maximum query.. but im repeatedly >>> getting wrong answer.. im stuck with this prob for a long time.. pls >>> help.. >>> >>> my code: >>> >>> #include >>> using namespace std; >>> #include >>> #include >>> int A[50010]; >>> int M[999]; >>> void initialize(int node, int b, int e) >>> { >>> if (b == e) >>> M[node] = b; >>> else >>> { >>> initialize(2 * node, b, (b + e) / 2); >>> initialize(2 * node + 1, (b + e) / 2 + 1,e); >>> if (A[M[2 * node]] >= A[M[2 * node + 1]]) >>> M[node] = M[2 * node]; >>> else >>> M[node] = M[2 * node + 1]; >>> } >>> } >>> int query(int node, int b, int e, int i, int j) >>> { >>> int p1, p2; >>> if (i > e || j < b) >>> return -; >>> if (b >= i && e <= j) >>> return M[node]; >>> p1 = query(2 * node, b, (b + e) / 2,i, j); >>> p2 = query(2 * node + 1, (b + e) / 2 + 1, e, i, j); >>> if (p1 == -) >>> return p2; >>> if (p2 == -) >>> return p1; >>> if (A[p1] >= A[p2]) >>> return p1; >>> return p2; >>> >>> } >>> >>> int main() >>> { >>> int n,i,t,j,count=0,k,size; >>> >>> scanf("%d%d",&n,&t); >>> >>>for (i=1;i<=n;i++) >>>scanf("%d",&A[i]); >>> >>> initialize(1,1,n); >>> for(i=0;i>> { >>>int x,y; >>>scanf("%d%d",&x,&y); >>>k=query(1,1,n,x,y); >>>if(!(x>>count++; >>> } >>> printf("%d",count); >>> return 0; >>> } >>> >>> >>> On 6/11/11, KK wrote: >>> > Search Topcoder Tutorial Range Minimum Query @ Google... >>> > By few intuitive changes u can implement Range Maximum Query as >>> > well... >>> > >>> > -- >>> > You received this message because you are subscribed to the Google >>> Groups >>> > "Algorithm Geeks" group. >>> > To post to this group, send email to algogeeks@googlegroups.com. >>> > To unsubscribe from this group, send email to >>> > algogeeks+unsubscr...@googlegroups.com. >>> > For more options, visit this group at >>> > http://groups.google.com/group/algogeeks?hl=en. >>> > >>> > >>> >>> >>> -- >>> radhika .. :) >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > radhika .. :) > -- radhika .. :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: SPOJ THRBL
yea.. now got ac.. :) mistake was k==y is also possible but xwrote: > k=query(x,y-1) > if(k==x) > count++ > with this change ur code ACs :) > > > On Sat, Jun 11, 2011 at 1:24 PM, Radhika Renganathan < > radi.coo...@gmail.com> wrote: > >> i did the same prob wit range maximum query.. but im repeatedly >> getting wrong answer.. im stuck with this prob for a long time.. pls >> help.. >> >> my code: >> >> #include >> using namespace std; >> #include >> #include >> int A[50010]; >> int M[999]; >> void initialize(int node, int b, int e) >> { >> if (b == e) >> M[node] = b; >> else >> { >> initialize(2 * node, b, (b + e) / 2); >> initialize(2 * node + 1, (b + e) / 2 + 1,e); >> if (A[M[2 * node]] >= A[M[2 * node + 1]]) >> M[node] = M[2 * node]; >> else >> M[node] = M[2 * node + 1]; >> } >> } >> int query(int node, int b, int e, int i, int j) >> { >> int p1, p2; >> if (i > e || j < b) >> return -; >> if (b >= i && e <= j) >> return M[node]; >> p1 = query(2 * node, b, (b + e) / 2,i, j); >> p2 = query(2 * node + 1, (b + e) / 2 + 1, e, i, j); >> if (p1 == -) >> return p2; >> if (p2 == -) >> return p1; >> if (A[p1] >= A[p2]) >> return p1; >> return p2; >> >> } >> >> int main() >> { >> int n,i,t,j,count=0,k,size; >> >> scanf("%d%d",&n,&t); >> >>for (i=1;i<=n;i++) >>scanf("%d",&A[i]); >> >> initialize(1,1,n); >> for(i=0;i> { >>int x,y; >>scanf("%d%d",&x,&y); >>k=query(1,1,n,x,y); >>if(!(x>count++; >> } >> printf("%d",count); >> return 0; >> } >> >> >> On 6/11/11, KK wrote: >> > Search Topcoder Tutorial Range Minimum Query @ Google... >> > By few intuitive changes u can implement Range Maximum Query as well... >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "Algorithm Geeks" group. >> > To post to this group, send email to algogeeks@googlegroups.com. >> > To unsubscribe from this group, send email to >> > algogeeks+unsubscr...@googlegroups.com. >> > For more options, visit this group at >> > http://groups.google.com/group/algogeeks?hl=en. >> > >> > >> >> >> -- >> radhika .. :) >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- radhika .. :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: SPOJ THRBL
k=query(x,y-1) if(k==x) count++ with this change ur code ACs :) On Sat, Jun 11, 2011 at 1:24 PM, Radhika Renganathan wrote: > i did the same prob wit range maximum query.. but im repeatedly > getting wrong answer.. im stuck with this prob for a long time.. pls > help.. > > my code: > > #include > using namespace std; > #include > #include > int A[50010]; > int M[999]; > void initialize(int node, int b, int e) > { > if (b == e) > M[node] = b; > else > { > initialize(2 * node, b, (b + e) / 2); > initialize(2 * node + 1, (b + e) / 2 + 1,e); > if (A[M[2 * node]] >= A[M[2 * node + 1]]) > M[node] = M[2 * node]; > else > M[node] = M[2 * node + 1]; > } > } > int query(int node, int b, int e, int i, int j) > { > int p1, p2; > if (i > e || j < b) > return -; > if (b >= i && e <= j) > return M[node]; > p1 = query(2 * node, b, (b + e) / 2,i, j); > p2 = query(2 * node + 1, (b + e) / 2 + 1, e, i, j); > if (p1 == -) > return p2; > if (p2 == -) > return p1; > if (A[p1] >= A[p2]) > return p1; > return p2; > > } > > int main() > { > int n,i,t,j,count=0,k,size; > > scanf("%d%d",&n,&t); > >for (i=1;i<=n;i++) >scanf("%d",&A[i]); > > initialize(1,1,n); > for(i=0;i { >int x,y; >scanf("%d%d",&x,&y); >k=query(1,1,n,x,y); >if(!(xcount++; > } > printf("%d",count); > return 0; > } > > > On 6/11/11, KK wrote: > > Search Topcoder Tutorial Range Minimum Query @ Google... > > By few intuitive changes u can implement Range Maximum Query as well... > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algogeeks@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com. > > For more options, visit this group at > > http://groups.google.com/group/algogeeks?hl=en. > > > > > > > -- > radhika .. :) > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: SPOJ THRBL
i did the same prob wit range maximum query.. but im repeatedly getting wrong answer.. im stuck with this prob for a long time.. pls help.. my code: #include using namespace std; #include #include int A[50010]; int M[999]; void initialize(int node, int b, int e) { if (b == e) M[node] = b; else { initialize(2 * node, b, (b + e) / 2); initialize(2 * node + 1, (b + e) / 2 + 1,e); if (A[M[2 * node]] >= A[M[2 * node + 1]]) M[node] = M[2 * node]; else M[node] = M[2 * node + 1]; } } int query(int node, int b, int e, int i, int j) { int p1, p2; if (i > e || j < b) return -; if (b >= i && e <= j) return M[node]; p1 = query(2 * node, b, (b + e) / 2,i, j); p2 = query(2 * node + 1, (b + e) / 2 + 1, e, i, j); if (p1 == -) return p2; if (p2 == -) return p1; if (A[p1] >= A[p2]) return p1; return p2; } int main() { int n,i,t,j,count=0,k,size; scanf("%d%d",&n,&t); for (i=1;i<=n;i++) scanf("%d",&A[i]); initialize(1,1,n); for(i=0;i wrote: > Search Topcoder Tutorial Range Minimum Query @ Google... > By few intuitive changes u can implement Range Maximum Query as well... > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- radhika .. :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.