QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#194931#3850. DJ DarkoSuiseisekiTL 0ms0kbC++142.8kb2023-09-30 23:42:142023-09-30 23:42:15

Judging History

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

  • [2023-09-30 23:42:15]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-09-30 23:42:14]
  • 提交

answer

#include <vector>
#include <cstdio>
#include <algorithm>
typedef long long ll;
const int Maxn=200000;
void read(int &a){
	a=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		a=a*10+c-'0';
		c=getchar();
	}
}
int n,q;
int a[Maxn+5],b[Maxn+5];
struct Segment_Node{
	ll lazy;
	ll sum;
	bool flag;
}seg[Maxn<<2|5];
std::vector<std::pair<ll,ll> > ans;
void push_up(int root){
	seg[root].flag=seg[root<<1].flag&&seg[root<<1|1].flag;
	if(seg[root].flag){
		if(seg[root<<1].lazy==seg[root<<1|1].lazy){
			seg[root].lazy=seg[root<<1].lazy;
		}
		else{
			seg[root].flag=0;
		}
	}
}
void build(int root=1,int left=1,int right=n){
	if(left==right){
		seg[root].lazy=a[left];
		seg[root].sum=b[left];
		seg[root].flag=1;
		return;
	}
	int mid=(left+right)>>1;
	build(root<<1,left,mid),build(root<<1|1,mid+1,right);
	seg[root].sum=seg[root<<1].sum+seg[root<<1|1].sum;
	push_up(root);
}
void push_down(int root){
	if(seg[root].flag){
		seg[root<<1].lazy=seg[root].lazy,seg[root<<1|1].lazy=seg[root].lazy;
	}
	else{
		seg[root<<1].lazy+=seg[root].lazy,seg[root<<1|1].lazy+=seg[root].lazy;
		seg[root].lazy=0;
	}
}
void modify(int l,int r,int a,int root=1,int left=1,int right=n){
	if(l>right||r<left){
		return;
	}
	if(l<=left&&r>=right){
		seg[root].lazy+=a;
		return;
	}
	push_down(root);
	int mid=(left+right)>>1;
	modify(l,r,a,root<<1,left,mid),modify(l,r,a,root<<1|1,mid+1,right);
	push_up(root);
}
void query(int l,int r,int root=1,int left=1,int right=n){
	if(l>right||r<left){
		return;
	}
	if(l<=left&&r>=right&&seg[root].flag){
		ans.push_back(std::make_pair(seg[root].lazy,seg[root].sum));
		return;
	}
	push_down(root);
	int mid=(left+right)>>1;
	query(l,r,root<<1,left,mid),query(l,r,root<<1|1,mid+1,right);
}
void update(int l,int r,ll v,int root=1,int left=1,int right=n){
	if(l>right||r<left){
		return;
	}
	if(l<=left&&r>=right){
		seg[root].flag=1,seg[root].lazy=v;
		return;
	}
	push_down(root);
	int mid=(left+right)>>1;
	update(l,r,v,root<<1,left,mid),update(l,r,v,root<<1|1,mid+1,right);
	push_up(root);
}
int main(){
	read(n),read(q);
	for(int i=1;i<=n;i++){
		read(a[i]);
	}
	for(int i=1;i<=n;i++){
		read(b[i]);
	}
	build();
	for(int i=1;i<=q;i++){
		int op;
		read(op);
		if(op==1){
			int l,r,x;
			read(l),read(r),read(x);
			modify(l,r,x);
		}
		else{
			int l,r;
			read(l),read(r);
			ans.clear();
			query(l,r);
			std::sort(ans.begin(),ans.end());
			ll sum_all=0;
			for(std::pair<ll,ll> i:ans){
				sum_all+=i.second;
			}
			ll cur_sum=0;
			ll ans_val=0;
			for(std::pair<ll,ll> i:ans){
				cur_sum+=i.second;
				if(cur_sum>=sum_all/2){
					ans_val=i.first;
					break;
				}
			}
			printf("%lld\n",ans_val);
			update(l,r,ans_val);
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

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
1810639671
467651597
5845907546
12257794515
5845907546
3115425130
6721490989
18103702061
1816209814
16129287869
16129287869
67041991431
53279411909
67041991431
67041991431
134083982862
259435333384
201125974293
50628055931
201377946469
551820645027
557772810816
2224636242676
206...

result: