Given array A and Q queries. Each query is l, r, x for every query you need to calc number of elements that less than x.

# | User | Rating |
---|---|---|

1 | tourist | 3843 |

2 | jiangly | 3705 |

3 | Benq | 3628 |

4 | orzdevinwang | 3571 |

5 | Geothermal | 3569 |

5 | cnnfls_csy | 3569 |

7 | jqdai0815 | 3530 |

8 | ecnerwala | 3499 |

9 | gyh20 | 3447 |

10 | Rebelz | 3409 |

# | User | Contrib. |
---|---|---|

1 | maomao90 | 171 |

2 | adamant | 163 |

2 | awoo | 163 |

4 | TheScrasse | 157 |

5 | nor | 153 |

6 | maroonrk | 152 |

6 | -is-this-fft- | 152 |

8 | Petr | 145 |

9 | orz | 144 |

9 | pajenegod | 144 |

Given array A and Q queries. Each query is l, r, x for every query you need to calc number of elements that less than x.

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/17/2024 23:37:19 (j3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

I think you can create for example fenwick tree or segment tree of order statistic trees and then sum up orders of x in all order statistic trees in [l, r].

EDIT: Or simply a merge sort tree.

You can solve offline the queries. 1) sort the queries in nondecreasing order regarding x; 2) build an array V with 2 parameters: the value of A[i] and i, the position, then sort V regarding first value; 3) after these operations, keep 2 pointers: you will start i from the first value from V and start with j from the first element in Q (sorted); update the values in the binary indexed tree unless V[i].first_parameter will be >= the x from actual j query, then calculate with BIT the answer like this: sum of first r values in BIT — sum of first l-1 values in BIT, then print this value.

For offline:Sort the queries by x,then for each query,add the elements(weren't added before)less than x into the i-th position of a BIT.Then check the sum in interval l and r.Complexity is .

For online:Discrete the array first.Then build a persistent segment tree.The i-th version contains the first i elements in the array.The difference between i and i-1 is the a[i]-th position is increased by 1.For a query,the answer is:the sum in [l,r] in the r-th tree minus the sum in [l,r] in the l-1-th tree.The Complexity is also .

Some mistakes here...

`For a query,the answer is:the sum in [l,r] in the r-th tree minus the sum in [l,r] in the l-1-th tree`

it should be:

`For a query,the answer is:the sum in [1,y] in the r-th tree minus the sum in [1,y] in the l-1-th tree(y is the number of elements strictly less than x in the whole array)`