Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

### OmaeWaMouShenDeiru's blog

By OmaeWaMouShenDeiru, 4 years ago, ,

Hey, some problems that requires cumulative frequencies asks for range update and range queries.

This problem in it's simplest form can be solved using segment tree with lazy propagation.

It can also be solved using binary indexed tree, but using it here differs from using it with range update and point query, or point update and range query.

Now I read couple of articales about it, but they all give a breef explanation about direct solution only, that two BITs needed.

I still can't understand why this problem occers and how was this solution invented.

Can someone please explain this topic.

Thanks :D

Edit: This is a link to one of the explanations for this problem.

• +6

By OmaeWaMouShenDeiru, history, 4 years ago, ,

Hey,

For problem: Lauren And Inversions

My code pass all but two huge cases.

What is wrong with my approach ?

• 0

By OmaeWaMouShenDeiru, history, 4 years ago, ,

This is the problem statement.

In My solution I precalculate the sortedness between existing values and save it in global variable sum

Then I calculate the value val[i][j] where i represent the index of a position with missing value in the given sequence and j represent the index of one of the missing values in vector want,

then I find the rest of sortedness values using TSP function, I used map because the state would be too big to fit in an array.

But the solution didn't pass.

Is there any other optimizations to be considered for my implementation.

Thanks.

• 0

By OmaeWaMouShenDeiru, 4 years ago, ,

Hey all,

So the best thing to do after a contest is to read editorals for problems that I read and couldn't come up with a solution during the contest.

But I find that most editorials are hardly helpful, because all I find is a direct explanation of the solution.

What I'm saying is that it is better to explain the steps you took to reach that solution, how you thought and came up with it, like sometimes I think of a bruteforce solution and then I conclude something that reduce it to better or simpler solution.

• +77

By OmaeWaMouShenDeiru, history, 5 years ago, ,

Hey all,

I always felt that programming contests differ from CF To TC to ACM etc,,

Do these contests have different styles in the problems they present.

And does improving my skills in one or two of them should reflect on the others ?

• +15

By OmaeWaMouShenDeiru, history, 5 years ago, ,

Hey,

What is the concept behind graph problems test case generation.

How can I write a random test case generator ?

• +7

By OmaeWaMouShenDeiru, history, 5 years ago, ,

Hello,

I'm trying to solve the last problem in this contest.

and this is my code, my idea is to change every strongly connected component into one node because the cost of travailing between it's nodes is ZERO, this can be done by removing all bridges and then applying union find on elements of the other edges.

Then I create new adjList using elements of the removed edges "i.e bridges", the new graph will form a tree.

Then I apply DFS two times to find the longest path in a tree.

Last step is to follow the longest path and save the sum of edges on the sides of each node, take the maximum sum between the left and right sum.

Sometimes it returns TLE and sometimes RTE.

What could be the mistake, and is there a better way to solve it.

Thanks.

EDIT: now this code gets WA

• +1

By OmaeWaMouShenDeiru, history, 5 years ago, ,

Hey,

Are there any plugins or tools available for codeforces contest, like those for TC ??

• +9

By OmaeWaMouShenDeiru, history, 5 years ago, ,

Hello CF and TC people,

I installed Greed plugin following steps in this link

But I keep getting this screen when I open any problem in the arena

PS: Im using elementary os luna

Any help would be appreciated.

Thanks :D

• +3

By OmaeWaMouShenDeiru, history, 5 years ago, ,

Hay codeforces, Is it possible to solve standard RMQ problem using binary indexed tree with conserving LogN queries ?

• +8

By OmaeWaMouShenDeiru, history, 5 years ago, ,

Hello,

This is an interesting data structure problem.

It can't be solved with regular insertion and print.

Who do you think it can be solved ??

• -3

By OmaeWaMouShenDeiru, history, 5 years ago, ,

Hello,

As I was trying to solve ZigZag problem on topcoder the weirdest thing happend.

#include <bits/stdc++.h>
using namespace std;
class ZigZag {
public:
int longestZigZag(vector<int> arr) {
int dp[55], state[55];
memset(dp, 1, sizeof dp);
cout << dp[0] << endl;
memset(state, 0, sizeof state);
for (int i = 0; i < arr.size(); ++i) {
for (int j = 0; j < i; ++j) {
if ((j == 0 || (arr[i] - arr[j] < 0 && state[j] > 0)
|| (arr[i] - arr[j] > 0 && state[j] < 0))
&& dp[j] + 1 > dp[i])
dp[i] = dp[j] + 1, state[i] = arr[i] - arr[j];
}
}
return dp[arr.size() - 1];
}
};


as I ran the given code, the cout statement gives 16843009.

I removed it and initialized every element int the first loop and it worked.

• -8

By OmaeWaMouShenDeiru, history, 5 years ago, ,

for this problem on spoj, Im getting WA and I don't know why !!

This is my code

Any hints ??

• 0

By OmaeWaMouShenDeiru, 5 years ago, ,

Hello,

In this blog, I would like to ask for your training experiences.

The ACM local contest will be in three month, and the regional contest is in December, and I believe I still have enough time to improve my skills.

I'm fast in reading problem statements and coding whenever I understand the problem completely. I know basics of graph theory problems, number theory, dynamic programming, and working on improving my data structure skills.

But whenever I participate in a codeforces contest, I feel there is a lot of skills I'm missing.

So it would be very kind of you to share or provide a good training schedule for the amount of time left before the coming contests.

• +7

By OmaeWaMouShenDeiru, 5 years ago, ,

hello,

for this problem, all I could come up with is to find all divisors of 'b' that are less than or equal to 't' using O(sqrt(n)) but It will get TLE for such input limits " < (1<<54)".

any hints for a better aproach ?

thanks :D

• -2

By OmaeWaMouShenDeiru, 5 years ago, ,

hey guys :D

I have this small math problem,

( a * b ) mod n = 1

Given a, n:

find the smallest value of 'b' that satisfies the equation above.

any Idea about how to find the answer better than linear time search.

• -3

By OmaeWaMouShenDeiru, 5 years ago, ,

Hey you guy's :D

Im wondering, given a number as input, what is the best way to find the smallest palindromic prime number greater than the given number.

Assume the answer fits in long long int as in c++

• -1

By OmaeWaMouShenDeiru, 5 years ago, ,

Hello,

I went through some problems that needs hashing or can be efficiently solved using hashing.

But it is still hard to understand this topic.

Thanks :D

• 0

By OmaeWaMouShenDeiru, 5 years ago, ,

Hello ,

I tried to solve this problem using subset sum algorithm and precalculation for all numbers which satisfy the given condition, But i got alot of TLE.

is there any fast subset sum algorithm better than O(n^2) ??

This is the problem :http://www.ahmed-aly.com/p.jsp?ID=172

And this is my code : Edit after AC :D

Thanks

• -2

By OmaeWaMouShenDeiru, 5 years ago, ,

For this problem on spoj: http://www.spoj.com/problems/ODDDIV/

Code Removed After AC :D

I went through the following steps to solve it: 1_ generate all primes to sqrt(1^10) to use them in prime factorization

2_ pre calculate number of divisors for numbers in range (1 — 100000)

3_ answer each query in O(n) time, I found that only perfect square numbers have odd number of divisors, so I only need to check if(fact_num[i] == k)from x to sqrt(y)

Any help to improve my time ??

• 0

By OmaeWaMouShenDeiru, 6 years ago, ,

Any ideas of how to solve this problem ??

http://uva.onlinejudge.org/external/100/10085.html

• 0

By OmaeWaMouShenDeiru, 6 years ago, ,

Hello, I would like ask to how is new rating calculated after each round ??

• -4

By OmaeWaMouShenDeiru, 6 years ago, ,

Hello codeforces community I wanna learn how to use Fread Fwrite for faster I/O.

If you have any useful example, I will be thankful :D.

• +3

By OmaeWaMouShenDeiru, 6 years ago, ,

Hello programmers,,

I read someones code a couple days earlier and i saw a piece of code using __typeof operator as a shortcut of a for loop. What is this operator and can it be used ?? Thanks :D