slow_coder4's blog

By slow_coder4, history, 7 years ago, In English

How can find the value from set given an index. suppose our set is st. st.insert(2); st.insert(6); st.insert(1);

Now i want to know the value of index 2 from set. Is there any logarithmic away? Thanks advance .

Full text and comments »

  • Vote: I like it
  • -2
  • Vote: I do not like it

By slow_coder4, history, 8 years ago, In English

Give me some tricks to solve it. problem : Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each d-query (i, j), you have to return the number of distinct elements in the subsequence ai, ai+1, ..., aj.

Input

Line 1: n (1 ≤ n ≤ 30000). Line 2: n numbers a1, a2, ..., an (1 ≤ ai ≤ 106). Line 3: q (1 ≤ q ≤ 200000), the number of d-queries. In the next q lines, each line contains 2 numbers i, j representing a d-query (1 ≤ i ≤ j ≤ n). Output

For each d-query (i, j), print the number of distinct elements in the subsequence ai, ai+1, ..., aj in a single line. Example

Input 5 1 1 2 1 3 3 1 5 2 4 3 5

Output 3 2 3

Full text and comments »

  • Vote: I like it
  • -13
  • Vote: I do not like it

By slow_coder4, history, 8 years ago, In English

problem :http://www.lightoj.com/volume_showproblem.php?problem=1111.. why its WA. Give me some critical case..

problem: K people are having a picnic. They are initially in N cities, conveniently numbered from 1 to N. The roads between cities are connected by M one-way roads (no road connects a city to itself).

Now they want to gather in the same city for their picnic, but (because of the one-way roads) some people may only be able to get to some cities. Help them by figuring out how many cities are reachable by all of them, and hence are possible picnic locations.

Input Input starts with an integer T (≤ 10), denoting the number of test cases.

Each case starts with three integers K (1 ≤ K ≤ 100), N (1 ≤ N ≤ 1000), M (1 ≤ M ≤ 10000). Each of the next K lines will contain an integer (1 to N) denoting the city where the ith person lives. Each of the next M lines will contain two integers u v (1 ≤ u, v ≤ N, u ≠ v) denoting there is a road from u to v.

Output For each case, print the case number and the number of cities that are reachable by all of them via the one-way roads.

Sample Input 1 2 4 4 2 3 1 2 1 4 2 3 3 4 Output for Sample Input Case 1: 2

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it

By slow_coder4, history, 8 years ago, In English

How can solve this-> http://www.lightoj.com/volume_showproblem.php?problem=1083 problem with segment tree. Please give me some hints.. Thanks..

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it

By slow_coder4, history, 8 years ago, In English

Give me some tips to solve- uva 10692 problem.. - problem link:https://uva.onlinejudge.org/external/106/10692.pdf

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

By slow_coder4, history, 8 years ago, In English

I got this problem TLE. help How can i handle my code . My code

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it