We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hello, I've done this in C++ and it works but I get timeouts in cases 6, 8 and 10. Can't see where I'd be able to optimise it more, any help?
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>usingnamespacestd;intn1,n2,n3,n4;structp{intx;inty;};typedefvector<p>VP;voidreflect(VP&points,charc,intI,intJ){if(c=='X')for(inti=I;i<J;++i)points[i].y=points[i].y*(-1);elsefor(inti=I;i<J;++i)points[i].x=points[i].x*(-1);}voidcounter(VP&points,intI,intJ){n1=0;n2=0;n3=0;n4=0;for(inti=I;i<J;++i){if(points[i].x>0andpoints[i].y>0)++n1;else{if(points[i].x<0andpoints[i].y>0)++n2;else{if(points[i].x<0andpoints[i].y<0)++n3;else++n4;}}}cout<<n1<<' '<<n2<<' '<<n3<<' '<<n4<<endl;}intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intn;cin>>n;VPpoints=vector<p>(n);for(intk=0;k<n;++k)cin>>points[k].x>>points[k].y;intq,I,J;cin>>q;charc;for(intk=1;k<=q;++k){cin>>c>>I>>J;if(c=='C'){counter(points,I-1,J);}else{reflect(points,c,I-1,J);}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Quadrant Queries
You are viewing a single comment's thread. Return to all comments →
Hello, I've done this in C++ and it works but I get timeouts in cases 6, 8 and 10. Can't see where I'd be able to optimise it more, any help?