QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#287855#3850. DJ DarkoLaStataleBlueRE 0ms0kbC++232.6kb2023-12-21 04:13:032023-12-21 04:13:03

Judging History

你现在查看的是最新测评结果

  • [2023-12-21 04:13:03]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-12-21 04:13:03]
  • 提交

answer

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

const long long INF = LLONG_MAX;
#define _mid (_l+_r)/2
struct SegmentTree{
	long long val,lazy;
	SegmentTree *left,*right;
	
	static SegmentTree* newSeg(long long val);
	
	void checkchild(){
		if(val!=INF){
			left = newSeg(val);
			right = newSeg(val);
			val=INF;
		}
	}
	
	void checklazy(){
		if(lazy!=0){
			if(left->val!=INF)left->val+=lazy;
			left->lazy+=lazy;
			if(right->val!=INF)right->val+=lazy;
			right->lazy+=lazy;
			lazy=0;
		}
	}
	
	void query(int l,int r,int _l,int _r,vector<array<long long,3>> &v){
		if(_r<l || _l>r)return;
		if(_l>=l && _r<=r && val!=INF){
			v.push_back({val,_l,_r});
			return;
		}
		
		checkchild();
		checklazy();
		
		left->query(l,r,_l,_mid,v);
		right->query(l,r,_mid+1,_r,v);
	}
	
	void update2(int l,int r,long long vval,int _l,int _r){
		if(_r<l || _l>r)return;
		if(_l>=l && _r<=r){
			if(val!=INF)val+=vval;
			lazy+=vval;
			return;
		}
		
		checkchild();
		checklazy();
		
		left->update2(l,r,vval,_l,_mid);
		right->update2(l,r,vval,_mid+1,_r);
	}
	
	void update(int l,int r,long long vval,int _l,int _r){
		if(_r<l || _l>r)return;
		if(_l>=l && _r<=r){
			val = vval;
			lazy = 0;
			left = right = nullptr;
			return;
		}
		
		checkchild();
		checklazy();
		
		left->update(l,r,vval,_l,_mid);
		right->update(l,r,vval,_mid+1,_r);
	}
};

const int VAL = 7'500'000;
SegmentTree vett[VAL];
int cc = 0;

SegmentTree* SegmentTree::newSeg(long long val){
	//if(cc==VAL)exit(0);
	
	int ind = cc++;
	
	vett[ind].val=val;
	vett[ind].lazy=0;
	vett[ind].left = vett[ind].right = nullptr;
	
	return &vett[ind];
}
#undef _mid

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,q;
	cin>>n>>q;
	
	SegmentTree *ds = SegmentTree::newSeg(0);
	
	vector<int> a(n+1);
	vector<long long> b(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ds->update(i,i,a[i],1,n);
	}
	
	for(int i=1;i<=n;i++){
		cin>>b[i];
		b[i]+=b[i-1];
	}
	
	for(int i=0;i<q;i++){
		int t;
		cin>>t;
		if(t==1){
			int l,r,x;
			cin>>l>>r>>x;
			ds->update2(l,r,x,1,n);
		}else{
			int l,r;
			cin>>l>>r;
			vector<array<long long,3>> res;
			ds->query(l,r,1,n,res);
			
			sort(res.begin(),res.end());
			long long sum=0;
			for(auto &i : res){
				//cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<" ecco\n";
				i[1]=b[i[2]]-b[i[1]-1];
				sum+=i[1];
			}
			
			long long curr=0;
			int ans;
			for(auto [a,b,c] : res){
				curr+=b;
				if(curr>=(sum+1)/2){
					ans=a;
					break;
				}
			}
			cout<<ans<<"\n";
			ds->update(l,r,ans,1,n);
		}
	}
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

200000 200000
185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...

output:

462406736
1749348519
1749348519
467651597
874061694
874061694
874061694
874061694
-1521749
874061694
-893932302
-664862892
-664862892
55224581
55224581
-190613756
-190613756
-190613756
-190613756
-190613756
-664862892
-442585932
-442585932
-442585932
-1193590577
-1000450919
-1000450919
-1000450919
-...

result: