$$$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 | MiFaFaOvO | 3681 |

2 | tourist | 3673 |

3 | Um_nik | 3493 |

4 | apiadu | 3397 |

5 | 300iq | 3317 |

6 | maroonrk | 3250 |

7 | Benq | 3230 |

8 | LHiC | 3229 |

9 | TLE | 3223 |

10 | ecnerwala | 3216 |

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

1 | antontrygubO_o | 192 |

2 | Errichto | 186 |

3 | tourist | 182 |

4 | vovuh | 170 |

5 | pikmike | 168 |

6 | ko_osaga | 165 |

7 | Radewoosh | 164 |

8 | Um_nik | 162 |

9 | 300iq | 155 |

10 | Petr | 153 |

$$$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: Apr/07/2020 03:29:44 (f3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|