이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;
const int MAX_N=1000010;
const lint INF=2.1e+15;
struct Seg
{
lint v,lazy;
void setv(lint vp,lint lp)
{
v=max(v+lp,vp);
lazy+=lp;
}
};
int n,m;
lint t1[MAX_N],t2[MAX_N],c1[MAX_N],c2[MAX_N],s1[MAX_N],s2[MAX_N];
lint ts1[MAX_N],ts2[MAX_N],ci[MAX_N];
Seg seg[MAX_N<<2];
vint endp[MAX_N];
void update_lazy(int i)
{
seg[i<<1].setv(seg[i].v,seg[i].lazy);
seg[i<<1|1].setv(seg[i].v,seg[i].lazy);
seg[i].v=-INF;
seg[i].lazy=0;
}
void update_(int i,int s,int e,int l,int r,lint add,lint cut)
{
if(s>=r || e<=l)return;
if(l<=s && e<=r)
{
seg[i].setv(cut,add);
return;
}
update_lazy(i);
update_(i<<1,s,(s+e)>>1,l,r,add,cut);
update_(i<<1|1,(s+e)>>1,e,l,r,add,cut);
}
lint find_(int i,int s,int e,int x)
{
if(s>x || e<=x)return 0;
if(s==x && x+1==e)return seg[i].v;
update_lazy(i);
return find_(i<<1,s,(s+e)>>1,x)+find_(i<<1|1,(s+e)>>1,e,x);
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> m;
for(int i=1;i<=n;i++)
{
cin >> t1[i] >> c1[i] >> s1[i];
ts1[i]=t1[i]+ts1[i-1];
}
for(int i=1;i<=m;i++)
{
cin >> t2[i] >> c2[i] >> s2[i];
ts2[i]=t2[i]+ts2[i-1];
}
for(int i=1;i<=n;i++)
{
int p=upper_bound(ts2,ts2+m+1,c1[i]-ts1[i])-ts2;
if(!p)continue;
endp[p].push_back(i);
}
for(int i=1;i<=m;i++)
ci[i]=upper_bound(ts1,ts1+n+1,c2[i]-ts2[i])-ts1;
for(int i=1;i<=m+1;i++)
{
vint cutted;
lint cut=-INF;
if(i<=m)
{
update_(1,0,n+1,0,ci[i],s2[i],cut);
cutted.push_back(ci[i]);
}
for(auto j : endp[i])
{
update_(1,0,n+1,j,n+1,s1[j],cut);
cutted.push_back(j);
}
sort(cutted.begin(),cutted.end());
for(auto p : cutted)
{
if(!p)continue;
cut=find_(1,0,n+1,p-1);
update_(1,0,n+1,p,n+1,0,cut);
}
cutted.clear();
}
cout << find_(1,0,n+1,n);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |