Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

DIVQUERY showing TLE even after using fastread with getchar_unlocked please help

$
0
0

I was submitting a problem in cookoff but it was showing time limit exceeded even after i used fastread function with getchar_unlocked please tell me how can i optimise it further

problem

here is my code

#include<stdio.h>


inline void fastread(int*);

int main(){

int t,i,n,p1,p2,k;
int *a;
fastread(&n);
a = (int*)malloc(sizeof(int)*n);
fastread(&t);
for(i=0;i<n;i++)
    fastread(&a[i]);
while(t--){
    int count = 0;
    fastread(&p1);
    fastread(&p2);
    fastread(&k);
    for(i=p1;i<=p2;i++){
        if(a[i-1]%k==0){
            count++;
        }
    }
    printf("%d\n",count);
}
return 0;
}

inline void fastread(int*a)

{

register char c=0;

while (c<33) c=getchar_unlocked();

*a =0;

while(c>33)

{

   *a = *a*10+c-'0';

   c=getchar_unlocked();
}

}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>