$$$a_1 = 1$$$

$$$a_2 = 5$$$

$$$a_n = a_{n-1} + n^2(a_{n-2}+1)$$$

**Prove** $$$a_n=(n+1)!-1$$$

P.S. Original problem

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

1 | Um_nik | 3538 |

2 | tourist | 3509 |

3 | Benq | 3473 |

4 | ecnerwala | 3446 |

5 | ksun48 | 3432 |

6 | maroonrk | 3404 |

7 | Radewoosh | 3383 |

8 | yosupo | 3324 |

9 | boboniu | 3300 |

10 | apiadu | 3238 |

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

1 | Errichto | 207 |

2 | Monogon | 199 |

3 | SecondThread | 194 |

4 | vovuh | 189 |

5 | Um_nik | 186 |

5 | antontrygubO_o | 186 |

7 | pikmike | 184 |

8 | Ashishgup | 182 |

9 | pashka | 169 |

10 | Radewoosh | 167 |

$$$a_1 = 1$$$

$$$a_2 = 5$$$

$$$a_n = a_{n-1} + n^2(a_{n-2}+1)$$$

**Prove** $$$a_n=(n+1)!-1$$$

P.S. Original problem

*n* ≤ 10^{5}, let's call them *A*, *B* and *C*.

Find number of such *i*-s that there's no such *j*, that (*A*_{i} > *A*_{j} and *B*_{i} > *B*_{j} and *C*_{i} > *C*_{j})

Why if **xor sum** of segment is equal to **sum** of segment, this condition is also satisfied for all **sub**segments of original segment?

I know that it's true when all bits in numbers are unique, but is it the only case when it's true, and if it is, then why?

Given an array of *n* positive integers called *a*

For each of *q* queries which are described with integers 1 ≤ *l* ≤ *r* ≤ *n*, output **xor of unique values in segment( l, r)**, i.e. if

1 ≤ *n*, *q* ≤ 10^{6}

for all *i*, 1 ≤ *a*_{i} ≤ 10^{9}

**TL: 3.5 secondsML: 256 megabytes**

How to solve it?

If it's possible, I'd like a solution which uses some of data structures listed below:**Segment TreeBinary Rise/LiftTrieMerge Sort Tree**

Input is consist of 1 ≤ *q* ≤ 2 * 10^{4} queries every of which are described with single positive integer *n* not exceeding 4 * 10^{6}.

Output is to print for each query: **Where:**

⌊*x*⌋ = whole part of number, i.e. max integer which's ≤ *x*

φ(*x*) is Euler Totient Function

OK, I can previously calculate phis of all numbers from 1 to 4 * 10^{6} and *P*_{i} for any *i*, 1 ≤ *i* ≤ 4 * 10^{6} in *O*(*nlogn*), but what's then? I don't know how to further optimize solution, because it is TLE with *O*(*n*) complexity per query.

Please, help me!

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/25/2020 16:35:43 (h3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|