列表

详情


NC206682. Precision

描述

As everyone knows, high precision is significant in the aircraft components. Now a factory has produced a component. To inspect the precision, the factory has hired you as chief analyst. Now you should finish the task.

The component is horizontal tail. The horizontal tail is an important airframe component to ensure longitudinal trimming, stability and control.

To simplify this problem, the thickness is sampled into a number sequence of length n. The i-th integer a_i represents the thickness of corresponding position of this component.

Due to some factors induced by fabrication technology and fitting process, structure errors are inevitable. So the sequence of length n is introduced, where c_i represents the volatility for the i-th position.

To finish the inspection, you have to do tests. In each test, you will choose an interval [l,r] and calculate its precision value. As chief analyst, you know the danger in some extreme case. So you want to change the volatility frequently and test it again.

The precision value A of [l, r] is defined as the following formula. The max-roughness is , and the min-roughness is . For simplicity, only the value of is needed.



You are required to finish the following operations:

输入描述

The first line contains two integers  denoting the length of sequence and the count of operations.

The second line contains n integers denoting the thickness of i-th position.

The third line contains n integers denoting the volatility of i-th position.

Following q lines, each line contains three integers:

- 0 p v, modify c_p to .
- 1 l r, calculate the precision value of interval

输出描述

For each quiry operation, output one line contain one integer denoting the precision value .

示例1

输入:

5 3
1 2 3 4 5
1 1 1 1 1
1 1 5
0 2 3
1 1 5

输出:

60
84

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 63ms, 内存消耗: 4444K, 提交时间: 2020-06-13 16:32:10

#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define LL long long
LL n,q,a[N],c[N],f[N],t[N],o,x,y;
LL lowbit(LL x){return x&-x;}
void change(LL x,LL c){while(x<N)t[x]+=c,x+=lowbit(x);}
LL ask(LL x){LL res=0;while(x)res+=t[x],x-=lowbit(x);return res;}
int main()
{
	scanf("%lld%lld",&n,&q);
	for(LL i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	for(LL i=1;i<=n;i++)
	  scanf("%lld",&c[i]),f[i]=a[i]*c[i];
	for(LL i=1;i<=n;i++)
	  change(i,f[i]);
	while(q--)
	  {
	  scanf("%lld%lld%lld",&o,&x,&y);
	  if(o)printf("%lld\n",4ll*(ask(y)-ask(x-1)));
	  else change(x,a[x]*y);
	  }
	return 0;
}

C++14(g++5.4) 解法, 执行用时: 85ms, 内存消耗: 4968K, 提交时间: 2020-06-16 12:11:25

#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&(-x))
int n,m,a[100005];
ll c[100005];
void update(int x,ll w){
	int i;
	for (i=x;i<=n;i+=lowbit(i)) c[i]+=w;
}
ll getsum(int x){
	int i; ll res=0;
	for (i=x;i;i-=lowbit(i)) res+=c[i];
	return res;
}
int main(){
	int i,x,y,z;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	memset(c,0,sizeof(c));
	for (i=1;i<=n;i++){
		scanf("%d",&x);
		update(i,a[i]*x);
	}
	while (m--){
		scanf("%d%d%d",&z,&x,&y);
		if (!z) update(x,a[x]*y);
		else printf("%lld\n",(getsum(y)-getsum(x-1))*4);
	}
	return 0;
}

上一题