CF1148H.Holy Diver

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array which is initially empty. You need to perform nn operations of the given format:

  • " aa ll rr kk ": append aa to the end of the array. After that count the number of integer pairs x,yx, y such that lxyrl \leq x \leq y \leq r and mex(ax,ax+1,,ay)=k\operatorname{mex}(a_{x}, a_{x+1}, \ldots, a_{y}) = k .

The elements of the array are numerated from 11 in the order they are added to the array.

To make this problem more tricky we don't say your real parameters of the queries. Instead your are given aa' , ll' , rr' , kk' . To get aa , ll , rr , kk on the ii -th operation you need to perform the following:

  • a:=(a+lans)mod(n+1)a := (a' + lans) \bmod(n + 1) ,
  • l:=(l+lans)modi+1l := (l' + lans) \bmod{i} + 1 ,
  • r:=(r+lans)modi+1r := (r' + lans) \bmod{i} + 1 ,
  • if l>rl > r swap ll and rr ,
  • k:=(k+lans)mod(n+1)k := (k' + lans) \bmod(n + 1) ,

where lanslans is the answer to the previous operation, initially lanslans is equal to zero. ii is the id of the operation, operations are numbered from 11 .The mex(S)\operatorname{mex}(S) , where SS is a multiset of non-negative integers, is the smallest non-negative integer which does not appear in the set. For example, mex({2,2,3})=0\operatorname{mex}(\{2, 2, 3\}) = 0 and mex({0,1,4,1,6})=2\operatorname{mex} (\{0, 1, 4, 1, 6\}) = 2 .

输入格式

The first line contains a single integer nn ( 1n21051 \leq n \leq 2 \cdot 10^5 ) — the length of the array.

The next nn lines contain the description of queries.

Each of them nn lines contains four non-negative integers aa' , ll' , rr' , kk' ( 0,a,l,r,k1090, \leq a', l', r', k' \leq 10^9 ), describing one operation.

输出格式

For each query print a single integer — the answer to this query.

输入输出样例

  • 输入#1

    5
    0 0 0 1
    0 1 0 5
    5 2 1 0
    5 2 1 0
    2 4 3 3
    

    输出#1

    1
    1
    2
    6
    3
    
  • 输入#2

    5
    2 0 0 2
    2 0 1 1
    0 0 2 0
    3 2 2 0
    0 2 3 0
    

    输出#2

    0
    0
    3
    0
    0
    

说明/提示

For the first example the decoded values of aa , ll , rr , kk are the following:

a1=0,l1=1,r1=1,k1=1a_1=0,l_1=1,r_1=1,k_1=1

a2=1,l2=1,r2=2,k2=0a_2=1,l_2=1,r_2=2,k_2=0

a3=0,l3=1,r3=3,k3=1a_3=0,l_3=1,r_3=3,k_3=1

a4=1,l4=1,r4=4,k4=2a_4=1,l_4=1,r_4=4,k_4=2

a5=2,l5=1,r5=5,k5=3a_5=2,l_5=1,r_5=5,k_5=3

For the second example the decoded values of aa , ll , rr , kk are the following:

a1=2,l1=1,r1=1,k1=2a_1=2,l_1=1,r_1=1,k_1=2

a2=2,l2=1,r2=2,k2=1a_2=2,l_2=1,r_2=2,k_2=1

a3=0,l3=1,r3=3,k3=0a_3=0,l_3=1,r_3=3,k_3=0

a4=0,l4=2,r4=2,k4=3a_4=0,l_4=2,r_4=2,k_4=3

a5=0,l5=3,r5=4,k5=0a_5=0,l_5=3,r_5=4,k_5=0

首页