### asifthegreat's blog

By asifthegreat, history, 3 weeks ago, ,

Hello, I have been trying a lot to solve Trail Maintence(LOJ), but I am getting RTE every time. I have been trying in many different ways, but at last I am getting RTE, don't know why. Can anyone help me debugging it please?

My code

•
• -8
•

By asifthegreat, history, 6 weeks ago, ,

Hello, I have tried a lot to solve MKTHNUM-spoj. For solving this , I have slightly changed the problem statement, it goes like this :

you are asked to find a number such that there are k-1 numbers less than that in range [l...r]

Then I made a merge sort tree and sorted the initial array and Binary Searched it. My time complexity is : O((log2(n))2) . I am getting Runtime Error in case 11 (i think). But couldn't find the bug :'( .

Updt: Now I am getting wrong answer. first 14 test cases ran smmothly

here goes my code :

#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;

const int N = 100099;
vector<int>tree[N*3];
int ara[N+12];

void build(int at ,int l,int r)
{
if(l == r){
tree[at].push_back(ara[l]);
return;
}
int mid = (l+r)/2;
build(at*2,l,mid);
build(at*2+1,mid+1,r);

merge(all(tree[at*2]),all(tree[at*2+1]),back_inserter(tree[at]));
}

int query(int at,int L,int R,int l,int r,int indx)
{
if(l > R or r < L)return 0;
if(L >= l and r >= R){
int pp = upper_bound(all(tree[at]),ara[indx])-tree[at].begin();
return pp;
}
int mid = (L+R)/2;
return query(at*2,L,mid,l,r,indx) + query(at*2+1,mid+1,R,l,r,indx);
}

int main()
{
int n,q,l,r,k;
scanf("%d%d",&n,&q);
for(int i= 1; i <= n;i++){
scanf("%d",&ara[i]);
}
build(1,1,n);
sort(ara+1,ara+1+n);
while(q--){
scanf("%d%d%d",&l,&r,&k);
int high = n,low = 1,mid,ans = -1;
int cnt = 0;
while(low <= high){
mid = (low+high)/2;
int pp = query(1,1,n,l,r,mid);
if(k <= pp){
ans = mid;
high = mid-1;
}
else low = mid+1;
}
printf("%d\n",ans);
}
return 0;
}


By asifthegreat, history, 3 months ago, ,

# Recently learned basics about Articulation Bridge and vertex...

•
• -20
•

By asifthegreat, history, 4 months ago, ,

Hello codeforces , I tried to solve Light Oj : 1110 — An Easy LCS but getting TLE , here is My code please help me to reduce my runtime :) thanks for advance :)

•
• -4
•

By asifthegreat, history, 6 months ago, ,

I saw someone to use a function instead of cin/scanf to input a number;

like that :

int n;
n = in();


where in() function is given bellow :

template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch =getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')break;}return (ng?-n:n);}  ?


i don't know what is faster , i also don't know , how scanf or cin works , can anyone please tell me ????

•
• -19
•

By asifthegreat, history, 6 months ago, ,

#### Lets Have fun , play a game :D :D :D

Hello codeforces , hello everybody , you all know , ACM ICPC is gonna be started , :) , and many of the participants are also CF users , and let's start a game for them , according to codeforces ratings , can you tell me which team is first ???

All you have to do , calculate their average ratings , and add them ( add the three ratings ) and divide them by 3 , Because there are 3 members in a team , and finally you will get a average rating , and according to them , you have to find the maximum rating of all the teams , and comment the name of their country and team/University name . and if you get board , you should not do it , you will suggest the avg ratings of a team in the comment box and i will fix it .

the winner will be included soon i wish :D :D

happy coding everybody :D :D good luck 1.

•
• -34
•

By asifthegreat, history, 8 months ago, ,

Hello codeforces , I have recently started learning BFS/DFS . and I tried solving following problem : Uva 10653 and My code

please someone help me debug my problem

•
• -27
•

By asifthegreat, history, 8 months ago, ,

Hello codeforces , I am a beginner , and I started learning Dynamic programming a few days ago . I haven't learned any specific algorithm yet , but i wanna practice some DP problems , can anyone suggest some easy DP problems please ??

•
• +1
•

By asifthegreat, history, 8 months ago, ,

Hello everybody , I have tried a lot to solve the light oj 1087 — Diablo problem .

My test sample output is not matching , I have tried a lot , I am a noob , please help me to debug my code . Why does it occur ??

my code : https://paste.ubuntu.com/26080511/

•
• -20
•

By asifthegreat, history, 9 months ago, ,

Hello , I can't realize why the judge output is much strange !!! problem link : http://codeforces.com/contest/451/problem/B

my code : https://paste.ubuntu.com/25939858/

judge status : http://codeforces.com/contest/451/submission/32225322

in my compiler , answer is okay , but where is the problem ?? I have also tested in different online compilers also

•
• -11
•

By asifthegreat, history, 9 months ago, ,

I have tried a lot to solve the "milking cow" problem of USACO . But WA in test 7 . I don't know what is the problem , i have tried multiple approaches , but it still wrong in test 7 . can you please help me to find my bug please ????

my code : https://paste.ubuntu.com/25901070/

problem source : http://train.usaco.org/usacoprob2?a=pxSIvVnwAXn&S=milk2

•
• -33
•

By asifthegreat, history, 9 months ago, ,

Just one question , am I doing any kinds of segmentation violation ?? such as -> wrong ara indexing or accessing memory out of bounds etc etc ???

memory limit : 256 mb

•
• -1
•

By asifthegreat, history, 10 months ago, ,

i am a beginner and i recently learned a bit about segment tree , i used segment tree in this solution , but i can't find my faults , can anyone please help me ?

By asifthegreat, history, 11 months ago, ,

everything seems okay , where is the problem ? can you explain ? problem link : http://codeforces.com/contest/855/problem/B

my code : https://paste.ubuntu.com/25608466/

•
• -21
•

By asifthegreat, history, 11 months ago, ,

I was solving problems in light online judge , and got "output Limit Exceeded" ! but I still don't know about it . Can you please tell me what does it mean ? and when it happens ? problem link :http://www.lightoj.com/volume_showproblem.php?problem=1212 my code : https://paste.ubuntu.com/25534441/

•
• -5
•

By asifthegreat, history, 12 months ago, ,

Hello everybody , how are you ? Today I am going to describe some contents (programming) Which can be helpful for contestants.

At first I assume that you all know about C/C++ language . But It doesn't matter . I think you also know about conditional logic , loop , datatype(input/output) , strings, array, function , basic bitwise operation etc . I think then you should learn lots of Mathematical terms such as :

Prime number , GCD , LCM , Eular's Totirnt Function , Bigmod , Modular inverse , Extended GCD , combinatorics, permutation , combination , inclusion exclusion principle ,probability , Expected value , Base conversation , Big integer , cycle , Gawssian elimination etc etc........

Then.....

you have to learn about sorting and searching . like : Insertion sort , bubble sort , merge sort , selection sort , merge sort , county sort etc . NOTE : THERE IS A THING NAMED "qsort" function is C language.....don't use it . There is an algorithm named "anti-qsort" . If you use it in codeforces , anyone can easily hack your solution because anti-qsort algorithm generates worst case for qsort and in the worst case , it's time complexity will be O(n^2) . But you can use Standerd Template Library .

Then........

You have to learn Binary search , Backtraking , ternary search etc...

Then.......

you have a task to learn lots of data structures . Such as : Linked list , Stack,Queue,heap , vector,graph,tree,segment tree , binary search tree , sqare root segmentation , disjoint set union , Lazy with proposition , lazy without proposition , Binary indexed tree , map , set , pair etc etc....

Then........

You haVe to learn greedy technique , Dyanamic programming , Graph algorithm , Flow , Adhoc , Geometry etc etc , I have summarized the contents bellow : 1. Dynamic Programming 2. Greedy 3 .Complete Search 4 . Flood Fill 5 . Shortest Path 6 . Recursive Search Techniques 7 . Minimum Spanning Tree 8 . Knapsack 9 . Computational Geometry 10 .Network Flow 11 . Eulerian Path 12 . Two-Dimensional Convex Hull 13 . BigNums 14 . Heuristic Search 15 . Approximate Search 16 . Ad Hoc Problems

If you clearup all those above , you will find a great programmer inside you , but mind it , It is not an easy tusk....You have to practice a lot . If you don't practice , you will never be able to be a good programmer .....!!!

SO , NO MORE TODAY ,,,, STAY WELL EVERYBODY,,,,ALWAYS TRY TO HELP OTHERS...HAPPY CODING !

•
• -19
•

By asifthegreat, history, 12 months ago, ,

Hello everybody . I have got some problems . In the last contest I solved a problem within 11 minutes . But someone hacked my submission . I still have no idea about hacking a submission . Please help me . How can I hack others' submission ? And how or why they can hack mine ? If there anyone who can help me ?????