记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 1ms 336.0 KiB
#2 Accepted 1ms 224.0 KiB
#3 Accepted 1ms 224.0 KiB
#4 Accepted 1ms 228.0 KiB
#5 Accepted 2ms 224.0 KiB
#6 Accepted 2ms 228.0 KiB
#7 Accepted 31ms 2.688 MiB
#8 Accepted 62ms 2.691 MiB
#9 Accepted 87ms 2.688 MiB
#10 Accepted 93ms 2.688 MiB
#11 Accepted 75ms 2.688 MiB
#12 Accepted 96ms 2.688 MiB
#13 Accepted 135ms 2.688 MiB
#14 Accepted 98ms 2.688 MiB
#15 Accepted 499ms 20.117 MiB
#16 Accepted 721ms 20.121 MiB
#17 Accepted 1077ms 20.117 MiB
#18 Accepted 1310ms 20.121 MiB
#19 Accepted 1584ms 20.117 MiB
#20 Accepted 1733ms 20.121 MiB

代码

#include<bits/stdc++.h>
using namespace std;
#define mid ((l+r)>>1)
const int maxn=1000010;
int n,m,t[maxn<<2],ad[maxn<<2],a[maxn],res,r1,r2,r3;

void build(int rt,int l,int r)
{
	if(l==r)
	{
		t[rt]=a[l];
		return;
	}
	build(rt<<1,l,mid);
	build(rt<<1|1,mid+1,r);
	t[rt]=min(t[rt<<1],t[rt<<1|1]);
}
void pushdown(int rt)
{
	t[rt<<1]+=ad[rt];
	t[rt<<1|1]+=ad[rt];
	ad[rt<<1]+=ad[rt];
	ad[rt<<1|1]+=ad[rt];
	ad[rt]=0;
	t[rt]=min(t[rt],min(t[rt<<1],t[rt<<1|1]));
}
void update(int rt,int l,int r,int L,int R,int k)
{
	if(L<=l&&r<=R)
	{
		ad[rt]+=k;
		t[rt]+=k;
		return;
	}
	if(ad[rt])pushdown(rt);
	if(L<=mid)update(rt<<1,l,mid,L,R,k);
	if(mid+1<=R)update(rt<<1|1,mid+1,r,L,R,k);
	t[rt]=min(t[rt<<1],t[rt<<1|1]);
}
void query(int rt,int l,int r,int L,int R)
{
	if(L<=l&&r<=R)
	{
		res=min(res,t[rt]);
		return;
	}
	if(ad[rt])pushdown(rt);
	if(L<=mid)query(rt<<1,l,mid,L,R);
	if(mid+1<=R)query(rt<<1|1,mid+1,r,L,R);
}



int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	build(1,1,n);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&r1,&r2,&r3);
		res=1e9+10;
		query(1,1,n,r2,r3);
		if(res<r1)
		{
			printf("-1\n%d",i);
			return 0;
		}
		else update(1,1,n,r2,r3,-r1);
	}
	printf("0");
	return 0;
}

信息

递交者
类型
递交
题目
P1042 借教室
比赛
随机真题赛第一轮(xhy&lfy讲题)
题目数据
下载
语言
C++
递交时间
2019-11-11 14:15:00
评测时间
2019-11-11 14:29:40
评测机
分数
100
总耗时
7618ms
峰值内存
20.121 MiB