# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
315342 |
2020-10-22T14:37:26 Z |
Dymo |
Trading (IZhO13_trading) |
C++14 |
|
481 ms |
18480 KB |
#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
trading.cpp: In function 'int main()':
trading.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
68 | freopen("GIDDY.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
trading.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
69 | freopen("GIDDY.out", "w", stdout) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
210 ms |
9592 KB |
Output is correct |
8 |
Correct |
231 ms |
11768 KB |
Output is correct |
9 |
Correct |
243 ms |
10360 KB |
Output is correct |
10 |
Correct |
244 ms |
7672 KB |
Output is correct |
11 |
Correct |
285 ms |
12408 KB |
Output is correct |
12 |
Correct |
286 ms |
9976 KB |
Output is correct |
13 |
Correct |
314 ms |
11896 KB |
Output is correct |
14 |
Correct |
305 ms |
9720 KB |
Output is correct |
15 |
Correct |
356 ms |
11768 KB |
Output is correct |
16 |
Correct |
368 ms |
11384 KB |
Output is correct |
17 |
Correct |
355 ms |
16120 KB |
Output is correct |
18 |
Correct |
390 ms |
18168 KB |
Output is correct |
19 |
Correct |
384 ms |
15224 KB |
Output is correct |
20 |
Correct |
481 ms |
18480 KB |
Output is correct |