为何UKE?
  • 板块学术版
  • 楼主a_small_penguin
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/9/26 19:45
  • 上次更新2024/9/26 21:27:36
查看原帖
为何UKE?
767155
a_small_penguin楼主2024/9/26 19:45
#include<bits/stdc++.h>
using namespace std;

struct node{
	long long l,r;
	long long ans;
};

int n,m;
long long d[100009];
node tree[400009];

long long ask(long long i,long long l,long long r){
	long long t;
	if(tree[i].r <= r && tree[i].l >= l) return tree[i].ans;
	t = 0;
	if(tree[i*2].r >= l) t+=ask(i*2,l,r);
	if(tree[i*2 + 1].l <= r) t+=ask(i*2+1,l,r);
	return t;
}

void build(long long i,long long l,long long r){
	long long mid = 0;
	tree[i].l = l;
	tree[i].r = r;
	if(l == r)
	{
		tree[i].ans =d[r];
		return;
	}
	mid = (l+r)/2;
	build(i*2,l,mid);
	build(i*2+1,mid+1,r);
	tree[i].ans = tree[i*2].ans+tree[i*2+1].ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long cnt=1;

	while(~scanf("%lld",&n)){
		printf("Case #%lld:\n",cnt++);
		for(int i = 1;i<=n;i++) cin >> d[i];
		cin >> m;
		build(1,1,n);
		for(int i = 1;i<=m;i++)
		{
			int p;
			cin >> p;
			if( p == 0)
			{
				long long x,y;
				cin >> x >> y; 
				if(x > y) swap(x,y);
				if(ask(1,x,y) == y-x+1) continue;
				for(int i = x;i<=y;i++) d[i] = sqrt(d[i]);
				build(1,1,n);
			}else
			{
				long long x,y;
				cin >> x >> y;
				if(x > y) swap(x,y);
				cout << ask(1,x,y) << "\n";
			}
		}
		puts("");
	}
}

https://www.luogu.com.cn/problem/SP2713

2024/9/26 19:45
加载中...