有一种绝望叫做无限PE hzau 1207 Candies (华中农业大学第五届程序设计大赛网络同步赛 I题)

本文介绍了一种使用线段树解决区间更新与区间内最大连续特定元素计数问题的方法。通过具体实例展示了如何构建线段树并实现两种操作:区间元素值更新和查询区间内最大连续特定元素的数量。

1207: Candies

Time Limit: 2 Sec   Memory Limit: 1280 MB
Submit: 161   Solved: 12
[ Submit][ Status][ Web Board]

Description

     Xiao Ming likes those N candies he collects very much. There are two kinds of candies, A and B. One day, Xiao Ming puts his candies in a row and plays games. And he can replace the Lth candy to the Rth candy with the same kind of candies. Now, he wonder that if he eats the Lth candy to Rth candy, he can eat how many B candy continuously at most. For each Xiao Ming’s query, give the number of the B candy he can eat continuously at most. 

Input

     In the first line, there is an integer T, indicates the number of test cases.

     For each case, there are two integers N and M in the first line, indicate the number of candies and the time of Xiao Ming’s operations.

     The second line is a N-length string consist of character A and B, indicates the row of candies Xiao Ming put.

     The next M line is Xiao Ming’s operations. There are two kind of operations:

          1. 1 L R v, indicate Xiao Ming replaces the Lth candy to the Rth candy with A candies (v==1) or B candies ( v == 2 ).

          2. 2 L R, indicate Xiao Ming wonder that there are how many continuous B candies between the Lth candy to the Rth candy most. 

Output

       In each case, the first line is “Case #k: “, k indicates the case number.

      For each query, output the number of the most continuous B candies. 

Sample Input

1
5 3
ABABB
2 1 3
1 2 3 2
2 1 3

Sample Output

Case #1:
1
2

题意:

给你一数组,数组的值只有0(A糖果)和1(B糖果)两种,对这个数组有两种操作:(1)把区间L到R的值更改为v, (2)询问从区间L到R最多有多少个1是连续的。

很明显这是个线段树区间更新与及区间合并的问题,对于线段树上的每个区间L到R只要维护三个值:lb(从区间左边开始有多少个1是连续的),rb(从区间右边开始到有多少个1是连续的),mb(区间L,R中最多1连续的个数)。

但是不知为何,博主我PE了4发,并不能找到问题的所在,只能GG了。下面是PE的代码!!!

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

const int maxn = 1e6 + 7;
struct node{
    int l, r, lazy, len;
    int lb, mb, rb;
    void Set_B(int key){ // 对区间内的 lb, mb, rb 进行更改
        if(key == 1) lb = mb = rb = 0;
        else lb = mb = rb = len;
    }
} tree[maxn<<2];
char z[maxn];

int Find_max(int s1, int s2, int s3){
    if(s2 > s1) s1 = s2;
    if(s3 > s1) s1 = s3;
    return s1;
}

void Push_up(int key){ // 向上更新, 区间合并
    int lson = key<<1, rson = key<<1|1;
    tree[key].lb = tree[lson].lb;
    tree[key].rb = tree[rson].rb;
    if(tree[lson].lb == tree[lson].len) tree[key].lb += tree[rson].lb;
    if(tree[rson].rb == tree[rson].len) tree[key].rb += tree[lson].rb;
    tree[key].mb = max(tree[lson].rb + tree[rson].lb, max(tree[lson].mb, tree[rson].mb));
}

void Push_down(int key){ // 向下更新
    if(tree[key].lazy != 0){
        int lson = key<<1, rson = key<<1|1;
        tree[lson].lazy = tree[rson].lazy = tree[key].lazy;
        tree[lson].Set_B(tree[key].lazy);
        tree[rson].Set_B(tree[key].lazy);
        tree[key].lazy = 0;
    }
}

void Buildtree(int l, int r, int key){ // 建树
    tree[key].l = l;
    tree[key].r = r;
    tree[key].len = r - l + 1;
    tree[key].lazy = 0;
    if(l == r){
        if(z[l] == 'A') tree[key].Set_B(1);
        else tree[key].Set_B(2);
        return;
    }
    int mid = (l + r) >> 1;
    Buildtree(l, mid, key<<1);
    Buildtree(mid+1, r, key<<1|1);
    Push_up(key);
}

void Update(int l, int r, int key, int w){ // 更新
    if(l <= tree[key].l && tree[key].r <= r){
        tree[key].lazy = w;
        tree[key].Set_B(w);
        return;
    }
    Push_down(key);
    int mid = (tree[key].l + tree[key].r) >> 1;
    if(l <= mid) Update(l, r, key<<1, w);
    if(mid < r) Update(l, r, key<<1|1, w);
    Push_up(key);
}

node Merge(node p, node q){ // 区间合并, 与向上更新相同
    node tmp;
    tmp.len = p.len + q.len;
    tmp.lb = p.lb;
    tmp.rb = q.rb;
    if(p.lb == p.len) tmp.lb += q.lb;
    if(q.rb == q.len) tmp.rb += p.rb;
    tmp.mb = max(p.rb + q.lb, max(p.mb, q.mb));
    return tmp;
}

node Query(int l, int r, int key){ // 询问
    if(l <= tree[key].l && tree[key].r <= r) return tree[key];
    Push_down(key);
    int mid = (tree[key].l + tree[key].r) >> 1;
    if(r <= mid) return Query(l, r, key<<1);
    else if(mid < l) return Query(l, r, key<<1|1);
    else return Merge(Query(l, mid, key<<1), Query(mid+1, r, key<<1|1));
}

int main(){
    int t, n, q, op, u, v, w;
    int num = 0;
    scanf("%d", &t);
    while(t --){
        scanf("%d %d", &n, &q);
        scanf("%s", z+1);
        Buildtree(1, n, 1);
        printf("Case #%d: \n", ++ num); // 这里很坑,如果后面没有空格会WA掉
        while(q --){
            scanf("%d %d %d", &op, &u, &v);
            if(op == 1){
                scanf("%d", &w);
                Update(u, v, 1, w);
            }
            else{
                node gg = Query(u, v, 1);
                printf("%d\n", Find_max(gg.lb, gg.mb, gg.rb));
            }
        }
    }
    return 0;
}


内容概要:本文详细记录了对一个Android ARM64静态ELF文件中字符串加密机制的逆向分析过程。该ELF文件的所有字符串均被加密,无法通过常规strings命令或IDA直接识别。作者通过分析发现,加密字符串存储在.rodata段,其解密所需信息(包括密文地址、长度和16位密钥)保存在.data.rel.ro段的40字节描述符中。核心解密函数sub_10F408采用自反的双pass流密码算法,结合固定密钥KEY_TERM(由.data段24字节数据计算得出),实现字节级非线性、位置与长度相关的加密。文章还复现了完整的Python解密脚本,并揭示了该保护机制的本质为代码混淆而非强加密,最终成功批量解密全部956条字符串,暴露程序真实行为,如shell命令模板、设备标识篡改、网络重置等操作。此外,文中还提及未启用的自定义壳框架及其反dump设计。; 适合人群:具备逆向工程基础的安全研究人员、二进制分析人员及对ELF保护技术感兴趣的开发者。; 使用场景及目标:①学习ELF二进制中字符串加密的典型实现方式与逆向突破口;②掌握从结构识别、函数追踪到算法还原的完整逆向流程;③理解“绑定二进制”的完整性校验设计及其局限性;④实践编写IDAPython脚本自动化提取与解密敏感数据。; 阅读建议:此资源以实战案例驱动,不仅展示技术细节,更强调逆向思维与验证方法,建议读者结合IDA调试环境,逐步跟随文中步骤进行动态分析与算法验证,深入理解每一步的推理依据。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值