记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 1ms 196.0 KiB
#2 Accepted 1ms 212.0 KiB
#3 Accepted 1ms 328.0 KiB
#4 Accepted 1ms 336.0 KiB
#5 Accepted 2ms 328.0 KiB
#6 Accepted 2ms 340.0 KiB
#7 Accepted 24ms 4.68 MiB
#8 Accepted 37ms 4.684 MiB
#9 Accepted 54ms 4.684 MiB
#10 Accepted 76ms 4.684 MiB
#11 Accepted 75ms 4.684 MiB
#12 Accepted 97ms 4.684 MiB
#13 Accepted 136ms 4.68 MiB
#14 Accepted 96ms 4.684 MiB
#15 Accepted 483ms 36.113 MiB
#16 Accepted 737ms 36.117 MiB
#17 Accepted 1046ms 36.113 MiB
#18 Accepted 1359ms 36.117 MiB
#19 Accepted 1656ms 36.117 MiB
#20 Accepted 1739ms 36.117 MiB

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=1000010;
int R[maxn];
int n,m,d,S,T;
inline int read()
{
  int x=0; char c=getchar();
  while(c<'0' || c>'9') c=getchar();
  while(c>='0' && c<='9') 
    x=(x<<1)+(x<<3)+c-'0',c=getchar();
  return x;
}

struct tree
{
  int l,r,Min,lazy;
}t[maxn<<2];

inline void push_up(int num)
{
  t[num].Min=min(t[num<<1].Min,t[num<<1|1].Min);
}

inline void push_down(int num)
{
  t[num<<1].lazy+=t[num].lazy;
  t[num<<1].Min+=t[num].lazy;
  t[num<<1|1].lazy+=t[num].lazy;
  t[num<<1|1].Min+=t[num].lazy;
  t[num].lazy=0;
}

void build(int l,int r,int num)
{
  t[num].l=l,t[num].r=r;
  if(l==r)
  {
  	t[num].Min=R[l];
	return; 
  }
  int mid=(l+r)>>1;
  build(l,mid,num<<1);
  build(mid+1,r,num<<1|1); 
  push_up(num);
}

void update(int l,int r,int ch,int num)
{
  if(l<=t[num].l && t[num].r<=r) 
  {
  	t[num].lazy+=ch;
	t[num].Min+=ch;
	return; 
  }
  if(t[num].lazy) push_down(num);
  if(l<=t[num<<1].r) update(l,r,ch,num<<1);
  if(r>=t[num<<1|1].l) update(l,r,ch,num<<1|1);
  push_up(num);
}

int Query(int l,int r,int num)
{
  if(l<=t[num].l && t[num].r<=r) return t[num].Min;
  if(t[num].lazy) push_down(num);
  int ans=INT_MAX;
  if(l<=t[num<<1].r) ans=min(ans,Query(l,r,num<<1));
  if(r>=t[num<<1|1].l) ans=min(ans,Query(l,r,num<<1|1));
  return ans;
}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=1;i<=n;i++) R[i]=read();
  build(1,n,1);
  for(int i=1;i<=m;i++)
  {
  	d=read(),S=read(),T=read();
  	if(Query(S,T,1)-d<0) 
    {
      printf("-1\n%d\n",i);
      return 0;
	}
	update(S,T,-d,1);
  }
  printf("0\n");
  return 0;	
} 

信息

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