Submission #339715

# Submission time Handle Problem Language Result Execution time Memory
339715 2020-12-26T04:47:13 Z tengiz05 Trading (IZhO13_trading) C++17
0 / 100
13 ms 19180 KB
#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(){prl = 0,prr = 0;}
};
node t[N*4];
void prop(int x, int len){
	if(t[x].prl == 0)return;
	if(len == 1){
		chmax(a[x-sz],t[x].prl);
	}else {
		int mid = (t[x].prr+t[x].prl)/2;
		assert(mid >= t[x].prl && mid <= t[x].prr);
		t[x*2].prl += t[x].prl;
		t[x*2].prr += mid;
		t[x*2+1].prl += mid+1;
		t[x*2+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*2);
	update(l, r, mid, R, x*2+1);
}

void solve(int test_case){
	int i, j;
	memset(t,0,sizeof(t));
	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

trading.cpp: In function 'void solve(long long int)':
trading.cpp:52:9: warning: unused variable 'j' [-Wunused-variable]
   52 |  int i, j;
      |         ^
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 19180 KB Output isn't correct
2 Halted 0 ms 0 KB -