快乐补题-SDNU_ACM_ICPC_2020_Winter_Practice_2st——E

复杂操作查询的线段树优化
本文介绍了一种使用线段树优化大规模数据集上复杂操作查询的方法,包括加法、乘法、赋值和求幂求和操作。通过线段树的数据结构,能够高效地处理大量操作并返回结果,同时提供了详细的AC代码实现。

Yuanfang is puzzled with the question below:
There are n integers, a 1, a 2, …, a n. The initial values of them are 0. There are four kinds of operations.
Operation 1: Add c to each number between a x and a y inclusive. In other words, do transformation a k<—a k+c, k = x,x+1,…,y.
Operation 2: Multiply c to each number between a x and a y inclusive. In other words, do transformation a k<—a k×c, k = x,x+1,…,y.
Operation 3: Change the numbers between a x and a y to c, inclusive. In other words, do transformation a k<—c, k = x,x+1,…,y.
Operation 4: Get the sum of p power among the numbers between a x and a y inclusive. In other words, get the result of a x p+a x+1 p+…+a y p.
Yuanfang has no idea of how to do it. So he wants to ask you to help him.

Input

There are no more than 10 test cases.
For each case, the first line contains two numbers n and m, meaning that there are n integers and m operations. 1 <= n, m <= 100,000.
Each the following m lines contains an operation. Operation 1 to 3 is in this format: “1 x y c” or “2 x y c” or “3 x y c”. Operation 4 is in this format: “4 x y p”. (1 <= x <= y <= n, 1 <= c <= 10,000, 1 <= p <= 3)
The input ends with 0 0.

Output

For each operation 4, output a single integer in one line representing the result. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10007.

Sample Input

5 5
3 3 5 7
1 2 4 4
4 1 5 2
2 2 5 8
4 3 5 3
0 0

Sample Output

307
7489

分析

沙雕线段树orz…和edu的线段树特别像,直接般的大佬的题解

AC代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<string>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>
#include<deque>
using namespace std;
#define left k*2
#define right k*2+1
const int N=10007;
struct node
{
    int l,r;
    int tag1,tag2,tag3;//分别表示加号,乘号,等号标记
}t[100005*4];
int n;
void Build(int l,int r,int k)
{
    t[k].l=l;
    t[k].r=r;
    t[k].tag1=0;
    t[k].tag2=1;
    t[k].tag3=-1;
    if(l==r)
    {
        t[k].tag3=0;//最底层要赋值为0
        return;
    };
    int mid=(l+r)/2;
    Build(l,mid,left);
    Build(mid+1,r,right);
}
void pushdown(int k)
{
    if(t[k].l==t[k].r)//没有子区间了不用退了
        return;
    if(t[k].tag3!=-1)//处理等号
    {
        t[left].tag3=t[right].tag3=t[k].tag3;//更新子区间等号标记
        t[left].tag2=t[right].tag2=1;
        t[left].tag1=t[right].tag1=0;//清空子区间加乘标记
        t[k].tag3=-1;
        return;
    }
    if(t[k].tag2!=1)//处理乘号
    {
        if(t[left].tag3!=-1)//如果子区间有等号标记,直接修改等号标记
            t[left].tag3=(t[left].tag3*t[k].tag2)%N;
        else//否则清空该子区间标记,进行子区间标记
        {
            pushdown(left);
            t[left].tag2=(t[left].tag2*t[k].tag2)%N;
        }
        if(t[right].tag3!=-1)//同理处理右区间
            t[right].tag3=(t[right].tag3*t[k].tag2)%N;
        else
        {
            pushdown(right);
            t[right].tag2=(t[right].tag2*t[k].tag2)%N;
        }
        t[k].tag2=1;
    }
    if(t[k].tag1!=0)//处理加号标记,和上面同理处理
    {
        if(t[left].tag3!=-1)
            t[left].tag3=(t[left].tag3+t[k].tag1)%N;
        else
        {
            pushdown(left);
            t[left].tag1=(t[left].tag1+t[k].tag1)%N;
        }
        if(t[right].tag3!=-1)
            t[right].tag3=(t[right].tag3+t[k].tag1)%N;
        else
        {
            pushdown(right);
            t[right].tag1=(t[right].tag1+t[k].tag1)%N;
        }
        t[k].tag1=0;//记得还原
    }
}
void update(int l,int r,int v,int d,int k)
{
    if(t[k].l==l&&t[k].r==r)
    {
        if(d==1)
        {
            if(t[k].tag3!=-1)//如果有等号标记,就直接修改等号标记
            {
                t[k].tag3=(t[k].tag3+v%N)%N;
            }
            else
            {
                pushdown(k);//否则清空该区间,进行标记
                t[k].tag1=(t[k].tag1+v%N)%N;
            }
        }
        else if(d==2)//同理
        {
            if(t[k].tag3!=-1)
            {
                t[k].tag3=(t[k].tag3*v%N)%N;
            }
            else
            {
                pushdown(k);
                t[k].tag2=(t[k].tag2*v%N)%N;
            }
        }
        else
        {
            t[k].tag3=v%N;
            t[k].tag1=0;
            t[k].tag2=1;
        }
        return;
    }
    pushdown(k);//向下更新
    int mid=(t[k].l+t[k].r)/2;
    if(r<=mid)
        update(l,r,v,d,left);
    else if(l>mid)
        update(l,r,v,d,right);
    else
    {
        update(l,mid,v,d,left);
        update(mid+1,r,v,d,right);
    }
}
int query(int l,int r,int p,int k)//查询
{
    if(t[k].l>=l&&t[k].r<=r&&t[k].tag3!=-1)//查到是查询区间的子区间且一段全为相同的数
    {
        int temp=1;
        for(int i=1;i<=p;i++)
            temp=(temp*t[k].tag3)%N;
        return ((t[k].r-t[k].l+1)%N*temp)%N;//注意要乘上长度
    }
    pushdown(k);
    int mid=(t[k].l+t[k].r)/2;
    if(r<=mid)
        return query(l,r,p,left)%N;
    else if(l>mid)
        return query(l,r,p,right)%N;
    else
    {
        return (query(l,mid,p,left)+query(mid+1,r,p,right))%N;
    }
}
int main()
{
    int i,j,k,m,d,x,y,c;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0&&m==0)
            break;
        Build(1,n,1);
        for(i=0;i<m;i++)
        {
            scanf("%d%d%d%d",&d,&x,&y,&c);
            if(d>=1&&d<=3)
            {
                update(x,y,c,d,1);
            }
            else
            {
                printf("%d\n",query(x,y,c,1)%N);
            }
        }
    }
    return 0;
}
————————————————
版权声明:本文为优快云博主「i-unique」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_37497322/article/details/76355061
Nano-ESG数据资源库的构建基于2023年初至2024年秋季期间采集的逾84万条新闻文本,从中系统提炼出企业环境、社会及治理维度的信息。其构建流程首先依据特定术语在德语与英语新闻平台上检索,初步锁定与德国DAX 40成分股企业相关联的报道。随后借助嵌入技术对文本段落执行去重操作,以降低内容冗余。继而采用GLiNER这一跨语言零样本实体识别系统,排除与目标企业无关的文档。在此基础上,通过GPT-3.5与GPT-4o等大规模语言模型对文本进行双重筛选:一方面判定其与ESG议题的相关性,另一方面生成简明的内容概要。最终环节由GPT-4o模型完成,它对每篇文献进行ESG情感倾向(正面、中性或负面)的判定,并标注所涉及的ESG具体维度,从而形成具备时序特征的ESG情感与维度标注数据集。 该数据集适用于多类企业可持续性研究,例如ESG情感趋势分析、ESG维度细分类别研究,以及企业可持续性事件的时序演变追踪。研究者可利用数据集内提供的新闻摘要、情感标签与维度分类,深入考察企业在不同时期的环境、社会及治理表现。此外,借助Bertopic等主题建模方法,能够从数据中识别出与企业相关的核心ESG议题,并观察这些议题随时间的演进轨迹。该资源以其开放获取特性与连续的时间覆盖,为探究企业可持续性表现的动态变化提供了系统化的数据基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值