Codeforces Round #326 (Div. 1)E. Duff as a Queen【线段树】+【线性基】

本文介绍了一个关于序列操作的问题,包含位运算和子序列Kheshtak计数的查询。通过构建数据结构来高效处理更新和查询操作,提供了一种解决方法。

E. Duff as a Queen

time limit per test

7 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Duff is the queen of her country, Andarz Gu. She's a competitive programming fan. That's why, when he saw her minister, Malek, free, she gave her a sequence consisting of n non-negative integers, a1, a2, ..., an and asked him to perform q queries for her on this sequence.

There are two types of queries:

  1. given numbers l, r and k, Malek should perform  for each l ≤ i ≤ r (, bitwise exclusive OR of numbers a and b).
  2. given numbers l and r Malek should tell her the score of sequence al, al + 1, ... , ar.

Score of a sequence b1, ..., bk is the number of its different Kheshtaks. A non-negative integer w is a Kheshtak of this sequence if and only if there exists a subsequence of b, let's denote it as bi1, bi2, ... , bix (possibly empty) such that (1 ≤ i1 < i2 < ... < ix ≤ k). If this subsequence is empty, then w = 0.

Unlike Duff, Malek is not a programmer. That's why he asked for your help. Please help him perform these queries.

Input

The first line of input contains two integers, n and q (1 ≤ n ≤ 2 × 105 and 1 ≤ q ≤ 4 × 104).

The second line of input contains n integers, a1, a2, ..., an separated by spaces (0 ≤ ai ≤ 109 for each 1 ≤ i ≤ n).

The next q lines contain the queries. Each line starts with an integer t (1 ≤ t ≤ 2), type of the corresponding query. If t = 1, then there are three more integers in that line, l, r and k. Otherwise there are two more integers, l and r. (1 ≤ l ≤ r ≤ n and 0 ≤ k ≤ 109)

Output

Print the answer of each query of the second type in one line.

Examples

input

Copy

5 5
1 2 3 4 2
2 1 5
1 2 2 8
2 1 5
1 1 3 10
2 2 2

output

Copy

8
16
1

Note

In the first query, we want all Kheshtaks of sequence 1, 2, 3, 4, 2 which are: 0, 1, 2, 3, 4, 5, 6, 7.

In the third query, we want all Khestaks of sequence 1, 10, 3, 4, 2 which are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15.

In the fifth query, we want all Kheshtaks of sequence 0 which is 0.

 

 

#include <bits/stdc++.h>

using namespace std;

struct L_B {
    long long d[31];

    void init() {
        memset(d, 0, sizeof(d));
    }

    bool insert(long long val) {
        for (int i = 30; i >= 0; i--)
            if (val & (1 << i)) {
                if (!d[i]) {
                    d[i] = val;
                    break;
                }
                val ^= d[i];
            }
        return val > 0;
    }

    int cnt() {
        int res = 0;
        for (int i = 30; i >= 0; --i) {
            if (d[i])res++;
        }
        return 1 << res;
    }
};

struct node {
    L_B lb;
    int lazy, w;
    int l, r;
} t[200004 * 4];

node merge(const node n1, const node n2) {
    node ret = n1;
    for (int i = 30; i >= 0; i--) {
        if (n1.lb.d[i])ret.lb.insert(n1.lb.d[i]);
        if (n2.lb.d[i])ret.lb.insert(n2.lb.d[i]);
    }
    ret.lb.insert(n1.w ^ n2.w);
    ret.w = n2.w;
    return ret;
}

int a[200004];

void pu(int rt) {
    int l = t[rt].l;
    int r = t[rt].r;
    int lazy = t[rt].lazy;
    t[rt] = merge(t[rt << 1], t[rt << 1 | 1]);
    t[rt].l = l, t[rt].r = r, t[rt].lazy = lazy;
}

void bu(int rt, int l, int r) {
    t[rt].l = l, t[rt].r = r, t[rt].lazy = 0;
    t[rt].lb.init();
    if (l == r) {
        t[rt].w = a[l];
    } else {
        int mid = (l + r) >> 1;
        bu(rt << 1, l, mid);
        bu(rt << 1 | 1, mid + 1, r);
        pu(rt);
    }
}

void pd(int rt) {
    if (t[rt].lazy == 0)return;
    t[rt << 1].lazy ^= t[rt].lazy;
    t[rt << 1 | 1].lazy ^= t[rt].lazy;
    t[rt << 1].w ^= t[rt].lazy;
    t[rt << 1 | 1].w ^= t[rt].lazy;
    t[rt].lazy = 0;
}

void upd(int rt, int l, int r, int xo) {
    if (t[rt].l >= l && t[rt].r <= r) {
        t[rt].lazy ^= xo;
        t[rt].w ^= xo;
    } else {
        pd(rt);
        int mid = (t[rt].l + t[rt].r) >> 1;
        if (l <= mid)upd(rt << 1, l, r, xo);
        if (r > mid)upd(rt << 1 | 1, l, r, xo);
        pu(rt);
    }
}

void que(int rt, int l, int r, node &ans) {
    if (t[rt].l >= l && t[rt].r <= r) {
        ans = merge(ans, t[rt]);
    } else {
        pd(rt);
        int mid = (t[rt].l + t[rt].r) >> 1;
        if (l <= mid) {
            que(rt << 1, l, r, ans);
        }
        if (r > mid) {
            que(rt << 1 | 1, l, r, ans);
        }
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    bu(1, 1, n);
    while (q--) {
        int op, l, r, k;
        scanf("%d", &op);
        if (op == 1) {
            scanf("%d%d%d", &l, &r, &k);
            upd(1, l, r, k);
        } else {
            scanf("%d%d", &l, &r);
            node ans;
            ans.lb.init();
            ans.w = 0;
            que(1, l, r, ans);
            printf("%d\n", ans.lb.cnt());
        }
    }
}

 

内容概要:本文主要介绍了一个基于Matlab实现的无人机空中通信仿真项目,旨在通过数值仿真手段研究无人机在空中作为通信节点时的通信性能、信号传播特性和网络拓扑行为。该仿真涵盖了无人机飞行轨迹建模、无线信道建模(如路径损耗、多普勒效应、阴影衰落等)、通信链路建立与中断判断、信号干扰分析以及网络性能评估(如吞吐量、延迟、连接可靠性等)。项目可能结合优化算法或智能控制策略,用于优化无人机位置部署或动态路径规划,以提升通信服务质量。整个仿真系统为研究人员提供了一套完整的工具链,用于验证新型无人机通信协议、协作机制和网络架构的有效性。; 适合人群:具备一定Matlab编程基础和通信原理基础知识,从事无人机、无线通信、网络优化等相关领域研究的研发人员和高校研究生。; 使用场景及目标:① 评估无人机作为空中基站或中继节点的通信覆盖能力和网络性能;② 设计和优化无人机集群的通信拓扑与协同策略;③ 验证新型无线资源分配、移动性管理和抗干扰算法在动态空地网络中的有效性。; 阅读建议:使用者应结合Matlab代码深入理解仿真模型的构建逻辑,重点关注通信信道模块和无人机运动学模型的耦合关系,并可根据实际研究需求,对仿真参数(如环境噪声、飞行速度、天线增益)进行调整,以开展针对性的对比实验和性能分析。
内容概要:本文围绕微电网中光伏发电系统经逆变器带负载的完整仿真模型展开研究,利用Simulink平台构建了从光伏阵列建模、DC-AC逆变器控制(包括PWM调制与电压电流双闭环控制)、并网策略到负载响应的全过程仿真系统。重点分析了系统在不同工况下的动态响应特性与电能质量表现,并对并网控制策略、最大功率点跟踪(MPPT)技术及系统稳定性进行了深入探讨和验证。该模型不仅可用于教学演示微电网的基本架构与运行机制,更为科研提供了可靠的仿真平台,支持对新型控制算法与系统优化方案的有效验证与评估。; 适合人群:具备一定电力电子技术、自动控制理论基础及Simulink/MATLAB操作经验的电气工程、自动化等相关专业的本科生、研究生及科研人员。; 使用场景及目标:①用于高校课程教学中微电网系统结构与运行原理的直观演示;②为科研工作者提供光伏发电并网系统的仿真验证平台,支持开展逆变器控制算法(如双闭环控制、MPPT)、系统稳定性分析及电能质量管理等关键技术的研究与优化。; 阅读建议:建议学习者结合Simulink仿真环境动手搭建模型,重点关注各功能模块间的信号传递关系与关键参数设置,并通过调整光照强度、温度、负载大小等外部条件,观察系统动态响应过程,从而深化对微电网运行特性的理解与掌握。
内容概要:本文围绕“多变量输入超前多步预测”的光伏功率预测问题,提出了一种基于CNN-BiLSTM混合深度学习模型的研究方法,并提供了完整的Matlab代码实现。该模型首先利用卷积神经网络(CNN)提取输入气象数据(如光照强度、温度、湿度等)中的局部关键特征,捕捉变量间的空间相关性;随后,通过双向长短期记忆网络(BiLSTM)充分挖掘时间序列数据中的长期依赖关系,既能利用历史信息,也能结合未来时刻的上下文信息,从而实现对未来多个时间步长的光伏功率进行高精度预测。研究重点在于处理多变量输入和满足超前多步预测的实际工程需求,有效提升了预测的准确性与鲁棒性。; 适合人群:具备一定机器学习和深度学习理论基础,熟悉Matlab编程,从事新能源发电预测、电力系统调度、时间序列分析等相关领域的研究人员和工程技术人员。; 使用场景及目标:① 解决光伏出力受多重气象因素影响的复杂非线性预测问题;② 实现未来一段时间(如未来24小时)的功率超前多步预测,为电网调度、储能管理和电力市场交易提供决策依据;③ 学习和复现先进的CNN与BiLSTM融合模型在能源预测领域的具体应用。; 阅读建议:使用者应重点关注模型的网络结构设计、多变量数据预处理流程以及多步预测的实现策略。建议结合提供的Matlab代码,自行准备或替换实际的光伏电站运行数据与气象数据,通过调整模型超参数(如卷积核大小、LSTM隐藏层维度、训练周期等)进行实验,以深入理解模型性能并将其应用于具体的科研或工程项目中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值