集训队专题(10)1002 A Simple Problem with Integers

本文介绍了一种涉及区间更新和查询的算法问题,通过构建特殊的数据结构实现高效处理。包括了对特定区间内的元素进行批量修改及快速获取指定位置元素值的方法。

A Simple Problem with Integers

Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4985    Accepted Submission(s): 1569


Problem Description
Let A1, A2, ... , AN be N elements. You need to deal with two kinds of operations. One type of operation is to add a given number to a few numbers in a given interval. The other is to query the value of some element.
 

Input
There are a lot of test cases. 
The first line contains an integer N. (1 <= N <= 50000)
The second line contains N numbers which are the initial values of A1, A2, ... , AN. (-10,000,000 <= the initial value of Ai <= 10,000,000)
The third line contains an integer Q. (1 <= Q <= 50000)
Each of the following Q lines represents an operation.
"1 a b k c" means adding c to each of Ai which satisfies a <= i <= b and (i - a) % k == 0. (1 <= a <= b <= N, 1 <= k <= 10, -1,000 <= c <= 1,000)
"2 a" means querying the value of Aa. (1 <= a <= N)
 

Output
For each test case, output several lines to answer all query operations.
 

Sample Input
  
4 1 1 1 1 14 2 1 2 2 2 3 2 4 1 2 3 1 2 2 1 2 2 2 3 2 4 1 1 4 2 1 2 1 2 2 2 3 2 4
 

Sample Output
  
1 1 1 1 1 3 3 1 2 3 4 1
 

Source
 

此题为区间更新,区间查询,但是在区间更新上,会有点要求,注意点就好

#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std;
const int maxn = 50010;
struct tree
{
    int l , r, k[12];
}a[4*maxn];
int num[maxn] , N , Q;
void build(int l , int r , int k)
{
    a[k].l = l;
    a[k].r = r;
    for(int i = 0; i < 12; i++) a[k].k[i] = 0;
    if(l != r)
	{
        int mid = (l+r)/2;
        build(l , mid , 2*k);
        build(mid+1 , r , 2*k+1);
    }
}
void update(int l , int r , int k , int lk , int lc)
{
    if(l <= a[k].l && a[k].r <= r) a[k].k[lk] += lc;
    else
	{
        int mid = (a[k].l+a[k].r)/2;
        if(mid >= r) update(l , r, 2*k , lk , lc);
        else if(mid < l) update(l , r , 2*k+1 , lk , lc);
        else
		{
            update(l , mid , 2*k , lk , lc);
            int tl = mid+1+(lk-(mid+1-l)%lk)%lk;
            if(tl <= r) update(tl , r , 2*k+1 , lk , lc);
        }
    }
}
int getAns(int k , int i)
{
    int ans = 0;
    for(int j = 1; j <= 10; j++)
	{
        if((i-a[k].l)%j == 0) ans += a[k].k[j];
    }
    return ans;
}
int query(int l , int r , int k)
{
    if(l <= a[k].l && a[k].r <= r) return getAns(k , l);
    else
	{
        int mid = (a[k].l+a[k].r)/2;
        int ans = getAns(k , l);
        if(mid >= r) return ans+query(l , r , 2*k);
        else return ans+query(l , r , 2*k+1);
    }
}
int main()
{
    while(~scanf("%d" , &N))
	{
        for(int i = 1; i <= N; i++) scanf("%d" , &num[i]);
    	build(1 , N , 1);
    	scanf("%d" , &Q);
    	int op , la, lb , lk , lc;
    	while(Q--)
		{
        	scanf("%d" , &op);
        	if(op == 1)
			{
            	scanf("%d%d%d%d" , &la , &lb , &lk , &lc);
            	update(la , lb , 1 , lk , lc);
        	}
			else
			{
            	scanf("%d" , &la);
            	printf("%d\n" , num[la]+query(la , la , 1));
        	}
    	}
    }
    return 0;
}


Nano-ESG数据资源库的构建基于2023年初至2024年秋季期间采集的逾84万条新闻文本,从中系统提炼出企业环境、社会及治理维度的信息。其构建流程首先依据特定术语在德语与英语新闻平台上检索,初步锁定与德国DAX 40成分股企业相关联的报道。随后借助嵌入技术对文本段落执行去重操作,以降低内容冗余。继而采用GLiNER这一跨语言零样本实体识别系统,排除与目标企业无关的文档。在此基础上,通过GPT-3.5与GPT-4o等大规模语言模型对文本进行双重筛选:一方面判定其与ESG议题的相关性,另一方面生成简明的内容概要。最终环节由GPT-4o模型完成,它对每篇文献进行ESG情感倾向(正面、中性或负面)的判定,并标注所涉及的ESG具体维度,从而形成具备时序特征的ESG情感与维度标注数据集。 该数据集适用于多类企业可持续性研究,例如ESG情感趋势分析、ESG维度细分类别研究,以及企业可持续性事件的时序演变追踪。研究者可利用数据集内提供的新闻摘要、情感标签与维度分类,深入考察企业在不同时期的环境、社会及治理表现。此外,借助Bertopic等主题建模方法,能够从数据中识别出与企业相关的核心ESG议题,并观察这些议题随时间的演进轨迹。该资源以其开放获取特性与连续的时间覆盖,为探究企业可持续性表现的动态变化提供了系统化的数据基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
Here is a C++ program that constructs a max heap with integers and prints it in the rotated form: ```cpp #include <iostream> #include <vector> using namespace std; // function to swap two integers void swap(int& a, int& b) { int temp = a; a = b; b = temp; } // function to heapify the given vector void heapify(vector<int>& arr, int n, int i) { int largest = i; // initialize largest as root int left = 2*i + 1; // left child index int right = 2*i + 2; // right child index // if left child is larger than root if (left < n && arr[left] > arr[largest]) largest = left; // if right child is larger than largest so far if (right < n && arr[right] > arr[largest]) largest = right; // if largest is not root if (largest != i) { // swap the root with largest element swap(arr[i], arr[largest]); // recursively heapify the affected sub-tree heapify(arr, n, largest); } } // function to build max heap void buildMaxHeap(vector<int>& arr, int n) { // start from the last non-leaf node and heapify each node for (int i = n / 2 - 1; i >= 0; i--) heapify(arr, n, i); } // function to print the heap in the rotated form void printRotatedHeap(vector<int>& arr, int n) { int height = log2(n) + 1; // height of the heap int index = 0; // current index in the heap int spaces = pow(2, height - 1) - 1; // number of spaces before the first element of the current level // print each level of the heap in the rotated form for (int i = 0; i < height; i++) { // print the spaces before the first element of the current level for (int j = 0; j < spaces; j++) cout << " "; // print the elements of the current level for (int j = 0; j < pow(2, i) && index < n; j++) { cout << arr[index++] << " "; // print the spaces between elements of the current level for (int k = 0; k < 2 * spaces + 1; k++) cout << " "; } // move to the next line and adjust the number of spaces for the next level cout << endl; spaces /= 2; } } int main() { int n; cout << "Enter the number of elements: "; cin >> n; vector<int> arr(n); cout << "Enter the elements: "; for (int i = 0; i < n; i++) cin >> arr[i]; // build max heap buildMaxHeap(arr, n); // print the heap in the rotated form cout << "Max heap in the rotated form:\n"; printRotatedHeap(arr, n); return 0; } ``` In this program, we first define a `swap` function to swap two integers, and a `heapify` function to heapify the sub-tree rooted at a given index `i` in the given vector `arr`. We then define a `buildMaxHeap` function to build the max heap from the given vector `arr`. Finally, we define a `printRotatedHeap` function to print the max heap in the rotated form. In the `main` function, we first read the number of elements and the elements themselves from the user using `cin`. We then build the max heap using `buildMaxHeap` function, and print the heap in the rotated form using `printRotatedHeap` function. The `printRotatedHeap` function uses the height of the heap to determine the number of levels, and the number of spaces before the first element of each level. It then prints each level of the heap in the rotated form, by printing the elements of the level followed by the spaces between elements.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值