object Main extends App {
  import scala.collection.mutable
  import scala.io.StdIn._

  val n = readInt
  val values = readLine.trim.map(_.asDigit).toArray
  val f = FTree.makeTree(values)
  val g = GTree.makeTree(values)
  val q = readInt
  for (_ ← 0 until q){
    val Array(l, r, b) = readLine.trim.split(' ').map(_.toInt)
    f.change(l - 1, r - 1, b)
    g.change(l - 1, r - 1, b)
    println(f.calculate - g.calculate)
  }
  object GTree {
     def makeTree(values: Array[Int]): GTree = {
       def sub(from: Int, until: Int): GTree = {
         if (from + 1 == until) GLeaf(from, values(from), values(from + 1))
         else {
           val mid = (from + until) / 2
           GNode(from, until, sub(from, mid), sub(mid, until))
         }
       }
       sub(0, values.length - 1)
     }
  }
  object FTree {
    def makeTree(values: Array[Int]): FTree = {
      def sub(from: Int, until: Int): FTree = {
        if (from + 1 == until) FLeaf(from, values(from))
        else {
          val mid = (from + until) / 2
          FNode(from, until - 1, sub(from, mid), sub(mid, until))
        }
      }
      sub(0, values.length)
    }
  }
  sealed trait GTree {
    def calculate: Int
    def change(from: Int, to: Int, newValue: Int): Unit
  }
  case class GLeaf(position: Int, var left: Int, var right: Int) extends GTree {
    override def calculate: Int = left * right
    override def change(from: Int, to: Int, newValue: Int): Unit = {
      if (from <= position && position <= to) left = newValue
      if (from <= position + 1 && position + 1 <= to) right = newValue
    }
  }
  case class GNode(positionFrom: Int, positionTo: Int, left: GTree, right: GTree) extends GTree {
    private[this] var changed: Int = -1
    private[this] var cached: Int = -1
    override def calculate: Int = {
      if (cached == -1){
        cached = if (changed == -1) left.calculate + right.calculate else changed * (positionTo - positionFrom)
      }
      cached
    }
    override def change(from: Int, to: Int, newValue: Int): Unit = {
      if (positionTo + 1 >= from && to >= positionFrom) {
        cached = -1
        if (from <= positionFrom && positionTo + 1 <= to) changed = newValue
        else {
          if (changed != -1){
            left.change(positionFrom, positionTo, changed)
            right.change(positionFrom, positionTo, changed)
            changed = -1
          }
          left.change(from, to, newValue)
          right.change(from, to, newValue)
        }
      }
    }
  }
  sealed trait FTree {
    def calculate: Int
    def change(from: Int, to: Int, newValue: Int): Unit
  }
  case class FLeaf(position: Int, var value: Int) extends FTree {
    override def calculate: Int = value
    override def change(from: Int, to: Int, newValue: Int): Unit = {
      if (from <= position && position <= to){
        value = newValue
      }
    }
  }
  case class FNode(positionFrom: Int, positionTo: Int, left: FTree, right: FTree) extends FTree {
    private[this] var changed: Int = -1
    private[this] var cached: Int = -1
    override def calculate: Int = {
      if (cached == -1) {
        cached = if (changed == -1) {
          left.calculate + right.calculate
        } else {
          changed * (positionTo - positionFrom + 1)
        }
      }
      cached
    }
    override def change(from: Int, to: Int, newValue: Int): Unit = {
      if (from <= positionTo && positionFrom <= to) {
        cached = -1
        if (from <= positionFrom && positionTo <= to){
          changed = newValue
        }else {
          if (changed != -1){
            left.change(positionFrom, positionTo, changed)
            right.change(positionFrom, positionTo, changed)
            changed = -1
          }
          left.change(from, to, newValue)
          right.change(from, to, newValue)
        }
      }
    }
  }

  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}
