Submission #672433

#TimeUsernameProblemLanguageResultExecution timeMemory
672433BaytoroTrading (IZhO13_trading)C++17
100 / 100
491 ms24384 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define int long long #define endl '\n' void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int INF=1e18,mod=1e9+7; const int N=3e5+5; int sz; vector<int> lazy,st; void innit(int x){ sz=1; while(sz<x) sz*=2; lazy.assign(2*sz-1,-INF); st.assign(2*sz-1,-INF); } void push(int x, int l, int r){ if(r-l==1) return; st[2*x+1]=max(st[2*x+1],lazy[x]); st[2*x+2]=max(st[2*x+2],lazy[x]); lazy[2*x+1]=max(lazy[2*x+1],lazy[x]); lazy[2*x+2]=max(lazy[2*x+2],lazy[x]); lazy[x]=-INF; } void update(int l, int r, int v, int x, int lx, int rx){ if(l>=rx || r<=lx) return; if(lx>=l && rx<=r){ st[x]=max(st[x],v); lazy[x]=max(lazy[x],v); return; } push(x,lx,rx); int md=(lx+rx)/2; update(l,r,v,2*x+1,lx,md); update(l,r,v,2*x+2,md,rx); st[x]=max(st[2*x+1],st[2*x+2]); } void update(int l, int r, int v){ update(l,r,v,0,0,sz); } int get(int i, int x, int lx, int rx){ if(rx-lx==1) return st[x]; int md=(lx+rx)/2; push(x,lx,rx); if(i<md) return get(i,2*x+1,lx,md); else return get(i,2*x+2,md,rx); } int get(int i){ return get(i,0,0,sz); } int n,m; void solve(){ cin>>n>>m; innit(n+1); while(m--){ int l,r,v;cin>>l>>r>>v; update(l,r+1,v-l,0,0,sz); } for(int i=1;i<=n;i++) cout<<max(0ll,get(i)+i)<<' '; } main(){ //ios; int T=1; //cin>>T; while(T--){ solve(); } }

Compilation message (stderr)

trading.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main(){
      | ^~~~
trading.cpp: In function 'void fopn(std::string)':
trading.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trading.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...