Hamim99's blog

By Hamim99, history, 4 years ago, In English

Can anyone give me hints for this proplem? https://www.spoj.com/problems/CNTPRIME/

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

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Segtree + lazy works

  • Run a sieve to find primes less than $$$10^{6}$$$
  • Read input and only store if each number is a prime or not
  • Build a sum segtree
  • For query of type 0 just do a lazy update on the segment x y ie. change all the values to isPrime(v)
  • For query of type 1, return the sum.

Sorry I don't know how to link SPOJ codes so I posted the code here

Code