Note that there are some explanatory texts on larger screens.

plurals
  1. POEfficient Algorithm Required For Range Queries
    primarykey
    data
    text
    <p>I want to know the best way to implement this (approach). I will bee given set of coordinates (x,y). I will then be queried based on those coordinates like <br/>1.C a b => where a and b are integer indexes in the initial set of coordinates. So I need to output the number of points that are in 1st ,2nd ,3rd and fourth quadrant that are in index range a to b.</p> <p><br/>2.X a b => where a and b are integer indexes in the initial set of coordinates. So I need to mirror the ath to bth indexed coordinates along x axis.</p> <p><br/>3.Y a b => where a and b are integer indexes in the initial set of coordinates. So I need to mirror the ath to bth indexed coordinates along y axis.</p> <p>there can be at most 100000 coordinates or points and 500000 such queries on them.</p> <p>I tried a brute force method looping through on every query but it had TLE(Time Limit Exceeded). </p> <p>What should I do in such type of questions?</p> <p>Here is my code</p> <pre><code>#include &lt;iostream&gt; #include &lt;stdio.h&gt; using namespace std; char flipX[4] = { 3, 2, 1, 0 }; char flipY[4] = { 1, 0, 3, 2 }; int main(int argc, char **argv) { int n,x,y; char c[100000]; scanf("%d",&amp;n); //coord *c=new coord[n]; for(int i=0;i&lt;n;i++) { scanf("%d",&amp;x); scanf("%d",&amp;y); if(x&lt;0 &amp;&amp; y&lt;0) c[i]=2; else if(x&gt;0 &amp;&amp; y&gt;0) c[i]=0; else if(x&gt;0 &amp;&amp; y&lt;0) c[i]=3; else c[i]=1; } int q,i,j,a,cnt[4]; char ch; scanf("%d",&amp;q); while(q--) { //cout&lt;&lt;"q:"&lt;&lt;q&lt;&lt;endl; cin&gt;&gt;ch; scanf("%d",&amp;i); scanf("%d",&amp;j); i--;j--; if(ch=='X') { //case 'X': for(a=i;a&lt;=j;a++) c[a]=flipX[c[a]]; // break; } else if(ch=='Y') { //case 'Y': for(a=i;a&lt;=j;a++) c[a]=flipY[c[a]]; // break; } else if(ch=='C') { cnt[0]=cnt[1]=cnt[2]=cnt[3]=0; for(a=i;a&lt;=j;a++) { cnt[c[a]]++; } printf("%d %d %d %d\n",cnt[0],cnt[1],cnt[2],cnt[3]); } } return 0; } </code></pre> <p>Please Help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload