# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
315342 | Dymo | Trading (IZhO13_trading) | C++14 | 481 ms | 18480 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=5e5+50;
const ll mod =1e9+7;
const ll base=113;
ll st[4*maxn];
ll la[4*maxn];
void dosth(ll id,ll left,ll right)
{
if (left==right||la[id]==0) return;
ll kc=(left+right)/2+1-left;
st[id*2]=max(st[id*2],la[id]);
la[id*2]=max(la[id*2],la[id]);
la[id*2+1]=max(la[id*2+1],la[id]+kc);
st[id*2+1]=max(st[id*2+1],la[id]+kc);
la[id]=0;
}
void update(ll id,ll left,ll right,ll x,ll y,ll val)
{
dosth(id,left,right);
if (x>right||y<left) return ;
if (x<=left&&y>=right)
{
st[id]=max(st[id],val+left-x);
la[id]=max(la[id],val+left-x);
dosth(id,left,right);
return ;
}
ll mid=(left+right)/2;
update(id*2,left,mid, x, y,val);
update(id*2+1,mid+1, right, x, y, val);
}
ll get(ll id,ll left,ll right,ll x )
{
dosth(id,left,right);
if (x>right||x<left) return 0;
if (left==right)
{
/* if (x==5)
{
cout <<st[id]<<endl;
}*/
return st[id];
}
ll mid=(left+right)/2;
return max(get(id*2,left,mid, x ), get(id*2+1, mid+1, right, x ));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen("GIDDY.inp", "r"))
{
freopen("GIDDY.inp", "r", stdin);
freopen("GIDDY.out", "w", stdout) ;
}
ll n, m;
cin>>n>>m ;
for (int i=1;i<=m;i++)
{
ll x, y, p;
cin>>x>> y>>p;
update(1,1,n,x,y,p);
}
for (int i=1;i<=n;i++)
{
cout <<get(1,1,n,i)<<" ";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |