# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
689675 | sudheerays123 | 거래 (IZhO13_trading) | C++17 | 464 ms | 30156 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 3e5+5 , INF = 1e18 , MOD = 1e9+7;
vector<ll> seg(4*N);
vector<pair<ll,ll>> lazy(4*N);
void build(ll node , ll left , ll right){
if(left == right){
seg[node] = 0;
lazy[node].first = 0;
lazy[node].second = 0;
return;
}
ll mid = (left+right)/2;
build(2*node,left,mid);
build(2*node+1,mid+1,right);
seg[node] = max(seg[2*node],seg[2*node+1]);
}
bool shouldIUpdate(ll beforeval , ll beforepos , ll newval , ll newpos , ll pos){
if(beforepos == 0) return true;
if(pos-newpos+newval >= pos-beforepos+beforeval) return true;
return false;
}
void propogate(ll node , ll left , ll right){
ll mid = (left+right)/2;
seg[node] = max(seg[node],right-lazy[node].second+lazy[node].first);
if(left != right){
if(shouldIUpdate(lazy[2*node].first,lazy[2*node].second,lazy[node].first,lazy[node].second,mid)) lazy[2*node] = lazy[node];
if(shouldIUpdate(lazy[2*node+1].first,lazy[2*node+1].second,lazy[node].first,lazy[node].second,right)) lazy[2*node+1] = lazy[node];
}
lazy[node].first = 0;
lazy[node].second = 0;
}
void update(ll node , ll left , ll right , ll ql , ll qr , ll val){
if(lazy[node].first) propogate(node,left,right);
ll mid = (left+right)/2;
if(left >= ql && right <= qr){
seg[node] = max(seg[node],right-ql+val);
if(left != right){
if(shouldIUpdate(lazy[2*node].first,lazy[2*node].second,val,ql,mid)) lazy[2*node] = make_pair(val,ql);
if(shouldIUpdate(lazy[2*node+1].first,lazy[2*node+1].second,val,ql,right)) lazy[2*node+1] = make_pair(val,ql);
}
return;
}
if(left > qr || right < ql) return;
update(2*node,left,mid,ql,qr,val);
update(2*node+1,mid+1,right,ql,qr,val);
seg[node] = max(seg[2*node],seg[2*node+1]);
}
ll query(ll node , ll left , ll right , ll ql , ll qr){
if(lazy[node].first) propogate(node,left,right);
if(left >= ql && right <= qr) return seg[node];
if(left > qr || right < ql) return 0;
ll mid = (left+right)/2;
ll l = query(2*node,left,mid,ql,qr);
ll r = query(2*node+1,mid+1,right,ql,qr);
return max(l,r);
}
void solve(){
ll n,m;
cin >> n >> m;
build(1,1,n);
while(m--){
ll l,r,x;
cin >> l >> r >> x;
update(1,1,n,l,r,x);
}
for(ll i = 1; i <= n; i++) cout << query(1,1,n,i,i) << " ";
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |