# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90894 | Hideo | Trading (IZhO13_trading) | C++14 | 250 ms | 11496 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 mk make_pair
#define pb push_back
const int N = 3e5 + 7;
const int INF = 1e9 + 7;
int lar[N], rar[N], xar[N], ans[N];
int t[4 * N];
int n, m, cx, id;
vector < pair < int , int > > v;
void upd (int v, int l, int r, int ql, int qr){
if (t[v] == r - l + 1 || (qr < l || r < ql))
return;
else if (r == l){
ans[l] = cx + l;
t[v] = 1;
return;
}
int mid = (l + r) / 2;
upd(v + v, l, mid, ql, qr);
upd(v + v + 1, mid + 1, r, ql, qr);
t[v] = t[v + v] + t[v + v + 1];
}
main(){
cin >> n >> m;
for (int i = 1; i <= m; i++){
scanf("%d%d%d", &lar[i], &rar[i], &xar[i]);
v.pb(mk(xar[i] - lar[i], i));
}
sort (v.begin(), v.end());
while (!v.empty()){
id = v.back().second, cx = v.back().first;
v.pop_back();
upd(1, 1, n, lar[id], rar[id]);
}
for (int i = 1; i <= n; i++){
printf("%d ", ans[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |