# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
339721 | tengiz05 | Trading (IZhO13_trading) | C++17 | 425 ms | 5740 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 int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 3e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int a[N], n, m, k, sz=1;
struct node{
int prl, prr;
};
node t[N*4];
void prop(int x, int len){
if(t[x].prl == 0)return;
if(len == 1){
assert(t[x].prl == t[x].prr);
chmax(a[x-sz],t[x].prl);
}else {
int mid = (t[x].prr+t[x].prl)>>1;
assert(mid >= t[x].prl && mid <= t[x].prr);
chmax(t[x<<1].prl,t[x].prl);
chmax(t[x<<1].prr,mid);
chmax(t[x<<1|1].prl,mid+1);
chmax(t[x<<1|1].prr,t[x].prr);
}t[x].prl = 0;
t[x].prr = 0;
}
int toup;
void update(int l, int r, int L, int R, int x){
prop(x, R-L);
if(L >= r || R <= l)return;
if(L >= l && R <= r){
t[x].prl = toup;
toup += R-L;
t[x].prr = toup-1;
prop(x, R-L);
return;
}int mid = (L+R)/2;
update(l, r, L, mid, x<<1);
update(l, r, mid, R, x<<1|1);
}
void solve(int test_case){
int i, j;
cin >> n >> m;
while(sz < n)sz<<=1;
while(m --){
int l, r, x;
cin >> l >> r >> x;
toup = x;
l--;
update(l, r, 0, sz, 1);
}
int S = sz;
int cnt = 2;
for(i=1;i<sz*2;i++){
assert(S);
prop(i, S);
if(__builtin_popcount(cnt) == 1)S>>=1;
cnt++;
}
for(i=0;i<n;i++)cout << a[i] << ' ' ;
cout << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int _T;
cin >> _T;
for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |