CF911D.Inversion Counting

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a__i < a__j. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3).

You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2].

After each query you have to determine whether the number of inversions is odd or even.

大小为 nn 的排列是一个长度为 nn 的数组,其中每个从 11 到 nn 的整数恰好出现一次。排列 pp 中的一个逆序对是指一对下标 (i, j)(i,\,j),满足 i>ji > j 且 ai<aja_i < a_j。例如,排列 [4, 1, 3, 2][4,\,1,\,3,\,2] 包含 44 个逆序对:(2, 1)(2,\,1)、(3, 1)(3,\,1)、(4, 1)(4,\,1)、(4, 3)(4,\,3)。

给定一个大小为 nn 的排列 aa 以及 mm 个对该排列的查询。每个查询由两个下标 ll 和 rr 表示,表示你需要将排列中区间 [l, r][l,\,r] 内的元素进行翻转。例如,若 a=[1, 2, 3, 4]a = [1,\,2,\,3,\,4],并执行查询 l=2, r=4l = 2,\,r = 4,则翻转后得到的排列为 [1, 4, 3, 2][1,\,4,\,3,\,2]。

每次查询后,你都需要判断当前排列中逆序对的总数是奇数还是偶数。

输入格式

The first line contains one integer n (1 ≤ n ≤ 1500) — the size of the permutation.

The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ n) — the elements of the permutation. These integers are pairwise distinct.

The third line contains one integer m (1 ≤ m ≤ 2·105) — the number of queries to process.

Then m lines follow, i-th line containing two integers l__i, r__i (1 ≤ l__i ≤ r__i ≤ n) denoting that i-th query is to reverse a segment [l__i, r__i] of the permutation. All queries are performed one after another.

第一行包含一个整数 nn(1≤n≤15001 \leq n \leq 1500)—— 排列的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \leq a_i \leq n)—— 排列的元素。这些整数两两不同。

第三行包含一个整数 mm(1≤m≤2⋅1051 \leq m \leq 2 \cdot 10^5)—— 需要处理的查询数量。

接下来是 mm 行,其中第 ii 行包含两个整数 li,ril_i, r_i(1≤li≤ri≤n1 \leq l_i \leq r_i \leq n),表示第 ii 个查询要求将排列中区间 [li, ri][l_i,\, r_i] 内的元素进行翻转。所有查询按顺序依次执行。

输出格式

Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise.

输出 mm 行。其中第 ii 行应为 odd(奇数),如果第 ii 次查询后的排列中逆序对数量为奇数;否则为 even(偶数)。

输入输出样例

  • 输入#1

    3
    1 2 3
    2
    1 2
    2 3

    输出#1

    odd
    even
  • 输入#2

    4
    1 2 4 3
    4
    1 1
    1 4
    1 4
    2 3

    输出#2

    odd
    odd
    odd
    even

说明/提示

The first example:

  1. after the first query a = [2, 1, 3], inversion: (2, 1);
  2. after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2).

The second example:

  1. a = [1, 2, 4, 3], inversion: (4, 3);
  2. a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3);
  3. a = [1, 2, 4, 3], inversion: (4, 3);
  4. a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).

第一个示例:

  1. 第一次查询后,a=[2,1,3]a = [2, 1, 3],逆序对为:(2,1)(2, 1);
  2. 第二次查询后,a=[2,3,1]a = [2, 3, 1],逆序对为:(3,1),(3,2)(3, 1), (3, 2)。

第二个示例:

  1. a=[1,2,4,3]a = [1, 2, 4, 3],逆序对为:(4,3)(4, 3);
  2. a=[3,4,2,1]a = [3, 4, 2, 1],逆序对为:(3,1),(4,1),(3,2),(4,2),(4,3)(3, 1), (4, 1), (3, 2), (4, 2), (4, 3);
  3. a=[1,2,4,3]a = [1, 2, 4, 3],逆序对为:(4,3)(4, 3);
  4. a=[1,4,2,3]a = [1, 4, 2, 3],逆序对为:(3,2),(4,2)(3, 2), (4, 2)。

输入解题思路,AI测评打分。不知道怎么写?

首页