HDU6703 CCPC-网络赛 1002 array (主席树 + set)/(权值线段树)

2020中国大学生程序设计竞赛(CCPC) - 网络选拔赛 1005 Lunch HDUOJ 6892 Lunch 题目链接 Problem Description Now it’s time for lunch. Today’s menu is chocolate! Though every baby likes chocolate, the appetites of babies are little. After lunch, there are still n pieces of chocolate remained: The length of the ith piece is 阅读详情

题目链接
题解:
解法一:
由于序列所有元素都是唯一的,在 1 ~ n 的范围内。
如果只有操作 2 ,就可以用主席树维护权值,查询在树中 a r + 1 a_{r+1} ar+1​ 到 a n a_n an​ 区间大于等于 k 的最小的数,但是还有操作 1。
操作 1 可以视为为操作 2 提供答案(因为加了一个很大的值,查询保证 k ≤ n k\leq n k≤n,那加了之后的值就查不到了),这样的话进行操作 1 ,就将 a p o s a_{pos} apos​ 插入 set 中,查询时主席树查一遍,set 中用 lower_bound 查询一遍,取最小值即可。时间复杂度O(mlogn)。
解法二(题解做法):
建一棵权值线段树维护权值的下标,每次操作一就是将该权值的下标设置为无穷大,操作二就是查询线段树中下标大于 r 的权值在 k ~ n 的最小值。
由于直接查可能会超时,所以线段树改为维护下标最大值方便剪枝。
解法一代码:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define PI acos(-1.0)
#define INF 0x3f3f3f3f3f3f3f3f
#define P pair<ll, int>
#define debug(x) cout << (#x) << ": " << (x) << " "
#define fastio ios::sync_with_stdio(false), cin.tie(0)
const ull mod = 1e9 + 7;
const int M = 15 + 10;
const int N = 100000 + 10;

int t, n, m, a[N];
struct node {
    int ls, rs;
    int num;
} tree[N<<5];
int rt[N], cnt;
set<int> s;

void build(int &now, int l, int r)
{
    now = ++cnt;
    tree[now].num = 0;
    if(l == r) return ;
    int mid = (l + r) >> 1;
    build(tree[now].ls, l, mid);
    build(tree[now].rs, mid + 1, r);
}

void add(int &now, int pre, int val, int l, int r)
{
    now = ++cnt;
    tree[now] = tree[pre];
    tree[now].num ++;
    if(l == r) return ;
    int mid = (l + r) >> 1;
    if(val <= mid) add(tree[now].ls, tree[pre].ls, val, l, mid);
    else add(tree[now].rs, tree[pre].rs, val, mid + 1, r);
}

int query(int p, int q, int L, int R, int l, int r)
{
    if(tree[q].num - tree[p].num == 0) return -1;
    if(l == r) {
        if(tree[q].num - tree[p].num) return l;
        return -1;
    }

    int mid = (l + r) >> 1, ans = -1;
    if(L <= mid) ans = query(tree[p].ls, tree[q].ls, L, R, l, mid);
    if(mid < R && ans == -1) ans = query(tree[p].rs, tree[q].rs, L, R, mid + 1, r);
    return ans;
}

int main()
{
    scanf("%d", &t);
    while(t --) {
        s.clear();
        cnt = 0;
        scanf("%d %d", &n, &m);
        s.insert(n + 1);
        build(rt[0], 1, n);
        for(int i = 1; i <= n; i ++) {
            scanf("%d", &a[i]);
            add(rt[i], rt[i - 1], a[i], 1, n);
        }
        int lastans = 0;
        for(int i = 1, op; i <= m; i ++) {
            scanf("%d", &op);
            if(op == 1) {
                int t1; scanf("%d", &t1);
                int pos = t1 ^ lastans;
                s.insert(a[pos]);
            } else {
                int t2, t3; scanf("%d %d", &t2, &t3);
                int r = t2 ^ lastans, k = t3 ^ lastans;
                lastans = query(rt[n], rt[r], k, n, 1, n);
                int temp = *(s.lower_bound(k));
                if(lastans != -1) lastans = min(lastans, temp);
                else lastans = temp;
                printf("%d\n", lastans);
            }
        }
    }
    return 0;
}

/*

  Rejoicing in hope, patient in tribulation.

*/

/*

             ,----------------,              ,---------,
        ,-----------------------,          ,"        ,"|
      ,"                      ,"|        ,"        ,"  |
     +-----------------------+  |      ,"        ,"    |
     |  .-----------------.  |  |     +---------+      |
     |  |                 |  |  |     | -==----`|      |
     |  |                 |  |  |     |         |      |
     |  |    Accepted _   |  |  |/----|`---=    |      |
     |  |                 |  |  |   ,/|==== OOO |      ;
     |  |                 |  |  |  // |(((( [33]|    ,"
     |  `-----------------`  |," .//| |((((     |  ,"
     +-----------------------+  //  | |         |,"
        /_)______________(_/  //`   | +---------+
   ___________________________/___  `,
  /  oooooooooooooooo  .o.  oooo /,   \,"-----------
 / ==ooooooooooooooo==.o.  ooo= //   ,`\--{)B     ,"
/_==__==========__==_ooo__ooo=_/`   /___________,"

*/

解法二代码:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define PI acos(-1.0)
#define INF 0x3f3f3f3f3f3f3f3f
#define P pair<ll, int>
#define debug(x) cout << (#x) << ": " << (x) << " "
#define fastio ios::sync_with_stdio(false), cin.tie(0)
const int mod = 1e9 + 7;
const int M = 15 + 10;
const int N = 100000 + 10;

int t, n, m, a[N];
int tree[N<<2];

void add(int pos, int id, int l = 1, int r = n, int rt = 1)
{
    if(l == r) {
        tree[rt] = id;
        return ;
    }
    int mid = (l + r) >> 1;
    if(pos <= mid) add(pos, id, l, mid, rt << 1);
    else add(pos, id, mid + 1, r, rt << 1 | 1);
    tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);
}

int query(int L, int R, int limit, int l = 1, int r = n, int rt = 1)
{
    if(tree[rt] <= limit) return -1;
    if(l == r) {
        if(tree[rt] > limit) return l;
        return -1;
    }
    int mid = (l + r) >> 1, ans = -1;
    if(L <= mid && tree[rt << 1] > limit) ans = query(L, R, limit, l, mid, rt << 1);
    if(mid < R && tree[rt << 1 | 1] > limit && ans == -1) ans = query(L, R, limit, mid + 1, r, rt << 1 | 1);
    return ans;
}

int main()
{
    scanf("%d", &t);
    while(t --) {
        scanf("%d %d", &n, &m);
        for(int i = 1; i <= n; i ++) {
            scanf("%d", &a[i]);
            add(a[i], i);
        }
        int lastans = 0;
        for(int i = 1, op; i <= m; i ++) {
            scanf("%d", &op);
            if(op == 1) {
                int t1; scanf("%d", &t1);
                int pos = t1 ^ lastans;
                add(a[pos], n + n);
            } else {
                int t2, t3; scanf("%d %d", &t2, &t3);
                int r = t2 ^ lastans, k = t3 ^ lastans;
                lastans = query(k, n, r);
                if(lastans == -1) lastans = n + 1;
                printf("%d\n", lastans);
            }
        }
    }
    return 0;
}

/*

  Rejoicing in hope, patient in tribulation.

*/

/*

             ,----------------,              ,---------,
        ,-----------------------,          ,"        ,"|
      ,"                      ,"|        ,"        ,"  |
     +-----------------------+  |      ,"        ,"    |
     |  .-----------------.  |  |     +---------+      |
     |  |                 |  |  |     | -==----`|      |
     |  |                 |  |  |     |         |      |
     |  |    Accepted _   |  |  |/----|`---=    |      |
     |  |                 |  |  |   ,/|==== OOO |      ;
     |  |                 |  |  |  // |(((( [33]|    ,"
     |  `-----------------`  |," .//| |((((     |  ,"
     +-----------------------+  //  | |         |,"
        /_)______________(_/  //`   | +---------+
   ___________________________/___  `,
  /  oooooooooooooooo  .o.  oooo /,   \,"-----------
 / ==ooooooooooooooo==.o.  ooo= //   ,`\--{)B     ,"
/_==__==========__==_ooo__ooo=_/`   /___________,"

*/

2017中国大学生程序设计竞赛-哈尔滨站 大力施工......(10/13)剩下的三个题好像不太能写啊?A.Palindrome(hdu6230)题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6230首先用Manacher处理出所有的回文半径,然后可以得到每个点覆盖的范围,问题转换成了,有多少对点,满足,i能覆盖j而且j也能覆盖i,我们按照回文半径从大到小进行排序,然后用线段树进行维护,然后... 阅读详情

相关推荐

[ADS]单端电感和差分电感的感值和Q值计算公式

单端电感和差分电感的感值和Q值计算公式

乾巽的博客 1万+

2019CCPC网络赛 杭电 6703 array(题解+代码)

由于序列中的每个值都是唯一的,并且值在 100000 范围内,所以可以用权值线段树来记录每个值出现的位置,并且维护区间最大出现位置。(1,r,k) 查询线段树中的[k,n]值域,取值大于 r 的最小下标值。(1,pos) 将pos的原来的值的位置修改成n+1(从原序列中删除)给定一个长度为 n 的序列,每个序列中的值都是唯一的。注意:输入的数据需要转换。

Lesords 240

海外支付实战:虚拟信用卡订阅ChatGPT Plus等服务的完整指南

在跨境数字服务消费中,支付环节常因地区限制、银行风控等因素受阻。其核心原理在于国际信用卡交易需通过发卡行风控系统,而国内银行对高频、小额或商户名非常规的境外线上交易敏感,导致成功率不稳定。为解决这一痛点,虚拟信用卡技术应运而生,它通过服务商生成关联预充值账户的虚拟卡号,提供地域灵活性与资金可控性,显著提升了支付通过率。这项技术的价值在于以较低学习成本,为个人用户打通了访问ChatGPT Plus、Midjourney、Claude Pro等前沿AI服务的支付通道。其典型应用场景包括订阅各类海外SaaS、内容

weixin_42531579的博客 1023

2022年CCPC桂林站C题Array Concatenation

下面就是看正序和逆序的数量的规律,其实正序要么是全部,要不一般是正序,一般是逆序

hjc的博客 1602

AGV舵轮选型实战:从核心参数到精准计算的完整指南

本文提供了一份详尽的AGV舵轮选型实战指南,强调从经验决策转向数据驱动。文章系统讲解了如何将工况需求转化为核心参数,并通过牵引力、扭矩、功率等关键计算步骤,指导工程师完成精准选型,避免因选型不当导致的运行故障与效率低下。

醉三国 495

手搓UDS Bootloader|全网独家复现0x10诊断会话控制、详解会话跳转规则与S3超时机制、助力ECU在线刷写、固件迭代、车规安全升级落地

在车载UDS诊断(ISO 14229)与Bootloader固件升级架构中,0x10诊断会话控制服务是所有高级诊断、固件刷写功能的前置核心与权限管控入口,属于UDS基础必实现服务。车载ECU通过分级会话模式,隔离常规故障诊断、高级标定、固件重编程等高、低权限操作,从协议层面保障车载电控系统的安全性与稳定性。多数嵌入式开发者开发UDS Bootloader时,仅简单实现会话切换报文应答,未吃透会话强制跳转规则、S3安全超时机制、会话权限绑定、APP在线刷写跳转逻辑。

getusushu的博客 465

2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛(解题报告)

1001 签到。输出A&B,当(A&B == 0)时特判。 1002 HDU - 6703 array 因为给的数字是1-n的全排列,对于操作2,可以转换为查询区间[r+1,n]里面第一个大于等于k的数字。(考虑到该区间可能没有大于等于k的数字,可以在n+1位置插入数字n+1,就一定能查询到了。所以每次查询区间[r+1,n+1]第一个大于等于k的数字。)对于操作1,可以将加了1e7...

ayyyyy_zc的博客 2261

SI案例分享--PCB通孔互连新技术的应用(VeCS)

本文介绍了VeCS的物理结构和制造过程,并通过全波仿真模拟和测量,分析了VeCS的电性能,并与传统的测量方法进行了比较。结果表明,由于有一个连续的参考平面,VeCS的TDR阻抗可以很容易地控制到目标阻抗,同时可以大大减轻信道上的串扰,的确是一种性能不错的PCB互连创新设计方案。

一只豌豆象的博客 2116

2019CCPC-网络选拔赛 HDU-6703 array (主席树 or 线段树)

CY提供的 主席树思路 https://blog.youkuaiyun.com/chenyume/article/details/100045386 题意:给出一个序列,保证序列是一个1~n的全排列,q次操作,两种类型,一是给a[i] a[i]a[i]加107 10^710 7 ,另一种是给出r,k,询问一个最小的数字x,使得x>=k x>=kx>=k,x不等于区间[1,r]内的任何一个数...

蒟蒻的最后的倔强 404

82、yolov11检测模型迁移瑞芯微rk3588和使用昇腾设备300i DUO卡推理 batch=1/3,支持昇腾NMS迁移npu推理

本文介绍了使用昇腾设备进行分割推理的测试流程,包括两种测试方式(cann+onnx和om)。首先验证300iDUO卡的可用性,随后创建Docker镜像和容器以搭建独立环境。通过从指定仓库拉取Ubuntu 20.04镜像,创建容器并映射目录。进入容器后安装必要组件(Python3、GCC等)和系统工具(pciutils、net-tools等),为后续模型转换和迁移做准备。整个流程旨在构建可交付给第三方的标准化测试环境。

sxj731533730 1202

2篇5章1节:实验流行病学的核心特征和设计原则

本文系统阐释实验流行病学的核心定义、四大核心特征、四大基本原则及主流设计类型,结合骨科、肿瘤科、儿科、精神科、内外妇儿及公共卫生等多学科临床实践案例,具象化解读人为干预、随机分组、平行对照、前瞻性设计的核心内涵与应用价值。同时,规范梳理对照、随机、盲法、重复四大研究基本原则,详细介绍临床试验、现场试验、社区试验三类主流研究设计的适配场景与应用差异。

MD Code 171

CCPC2019网络赛 array【后缀数组】【主席树】【线段树上二分】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6703 #include <bits/stdc++.h> #define rep(i, a, b) for(int i = (a); i <= (b); i++) #define per(i, a, b) for(int i = (a); i >= (b); i++) #de...

蒟蒻 lxw的博客 375

Windows 11 安装 OpenClaw(龙虾):不用WSL、不用虚拟机、启动、使用、停止、卸载

本文详解 Windows 11 原生安装 OpenClaw(龙虾)全流程,无需 WSL 或虚拟机。涵盖环境配置、安全警示、模型接入(如通义千问)及技能初始化。提供启动、文件自动化操作、停止与卸载的完整指南,并附常见认证过期解决方案。助您快速部署本地 AI 智能体,实现电脑操作自动化,提升工作效率。

寒水馨 · 轻量级技术文档 · hanshuixin.org 900

CCPC 2019 网络赛 1002 array (权值线段树)

HDU 6703 array 题意:   给定一个数组 \(a_1,a_2, a_3,...a_n\) ,满足 \(1 \le a[i]\le n\) 且 \(a[i]\) 互不相同。   有两种操作:1. 将 \(a_{pos}\) 的值加上 100000000;2. 询问不等于任何 \(a[i], (1 \le i \le r)\) 且不小于 \(k\) 的最小值。 思路: ...

weixin_30879833的博客 201

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

HDU 6703 array 2019CCPC网络选拔赛 1002 (线段树/权值线段树/主席树+set)

array Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1356Accepted Submission(s): 522 Problem Description You are given an arraya1,...

pxlsdz的博客 445

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

CCPC2019网络赛1002 array (主席树)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6703   题意:给你一个n的全排列A,然后给m个操作,第一类操作给一个数k,将A[k^lastans]增加1000000;第二类操作在区间给两个数v,k,要求一个最小的ans,不与区间A[1,v^lastans]中任意一个数相等,并且不小于k^lastans。   先看如果没有进行过第一...

weixin_30552635的博客 156

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

array(2019CCPC网络预选赛 hdu6703主席树+set)主席树求大于等于k的最小值

Problem Description You are given an array a1,a2,…,an(∀i∈[1,n],1≤ai≤n). Initially, each element of the array is unique. Moreover, there are m instructions. Each instruction is in one of the following ...

starlet_kiss的博客 598

2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 解题报告

1001 ^&^ Problem Description Bit operation is a common computing method in computer science ,Now we have two positive integers A and B ,Please find a positive integer C that minimize the value o...

1万+

2019CCPC网络 B.array (线段树)

大致题意 给定一个1-n的排列,有m次操作。(n<=100000,m<100000); 操作1:给定pos=pos^lastans ,将a[pos]加1e7 操作2:给定r=r^ lastans,k=k^lastans ,询问大于等于k的最小的数,而且在区间1-r内不包含的数。 思路 因为强制在线,只能数据结构。一开始没看见是排列,想了半天… 然后考虑权值线段树,a[i]表示数值i出现...

lalalafloat的博客 279

2019CCPC网络赛——array(权值线段树)

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=6703 题目大意: 给出一个n(n<1e5)个元素的数组A,A中所有元素都是不重复的[1,n]。 有两种操作: 1.将pos位置的元素+1e7 2.查询不属于[1,r]中的最小的>=k的值。 强制在线,上次计算结果和输入值xor得到区间。 比赛的时候感觉这道题有点线段树...

alimjan198854的博客 294

2019CCPC网络赛 HDU6703 - array(线段树查询时剪枝)

链接:B - array 题意: 给出nnn个数的数组a1,a2,⋯&ThinSpace;,an&ThickSpace;(∀i∈[1,n],1≤ai≤n≤105)a_1,a_2,\cdots,a_n\;(∀i∈[1,n],1≤a_i≤n\le10^5)a1​,a2​,⋯,an​(∀i∈[1,n],1≤ai​≤n≤105),其中aaa各不相同。 给出m&ThickSpace;...

Plus Ultra! 406

2019 CCPC 网络选拔 array

题意 给一个\(1\)到\(n\)的排列 现在有\(m\)个操作,每个操作是下面的一种: \((1,pos)\),指把\(pos\)位上的数增加\(10,000,000\) \((2,r,k)\),询问操作,你需要输出一个数满足下列三个条件 这个数不等于\(a_i(1\leq i \leq r)\)中的任意一个 这个数不小于\(k\) 是满足上两个条件的数中的最小的一个 \(T\...

bansai5236的博客 212

2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 array

http://acm.hdu.edu.cn/showproblem.php?pid=6703 #include <iostream> #include <cstring> #include <queue> #include <vector> #include <algorithm> #include <cstdio> #...

newhonor 436

2019 CCPC - 网络选拔赛 1002 主席树

传送门 来自于xls 解法:如果这题不带修改操作,相信大家都会做,我就来讲讲怎么处理修改,对于每次修改操作,我不需要真的去修改它,而是把修改的那个元素插入set中去,然后每次查询,我们不带修改查一个答案v1,然后再去set里找第一个大于等于k的v2,min(v1, v2)就是答案。证明:如果v2 >= v1,不影响答案,如果v2<v1,,假设v2在数组中的位置 > r,那么...

Pikachu的博客 347

2018中国大学生程序设计竞赛 - 网络选拔赛 Tree and Permutation

Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 69    Accepted Submission(s): 26   Problem Description There are N vert...

哇-WA 的博客 417

2018中国大学生程序设计竞赛 - 网络赛

1001 Buy and Resell Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1011    Accepted Submission(s): 313 Problem Description The Power Cube ...

紫芝的博客 5922
上一篇: 2019牛客暑期多校训练营(第三场)G Removing Stones (分治+RMQ)
下一篇: HDU6705 CCPC网络赛 path
ttoobne
博客等级 码龄9年 13粉丝 59原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值