# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90880 | YottaByte | Trading (IZhO13_trading) | C++14 | 13 ms | 548 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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define pb push_back
#define mk make_pair
#define fr first
#define endl '\n'
#define sc second
#define pii pair < int, int >
#define piii pair < int, pair < int, int > >
const int N = 3e5 + 1;
int n, m, c;
int t[N * 4], h[N * 4];
vector < pair < pii, pii > > v;
void push(int v, int l, int r)
{
if(h[v])
{
t[v] = (r - l + 1) * h[v];
h[v + v] = h[v];
h[v + v + 1] = h[v];
h[v] = 0;
}
}
void upd(int ql, int qr, int x, int v = 1, int l = 1, int r = n)
{
push(v, l, r);
if(l > qr || r < ql) return;
//cout << l << " " << r << endl;
if(ql <= l && r <= qr)
{
h[v] = x;
push(v, l, r);
return;
}
else
{
int mid = l + r >> 1;
upd(ql, qr, x, v + v, l, mid);
upd(ql, qr, x, v + v + 1, mid + 1, r);
}
t[v] = t[v + v] + t[v + v + 1];
}
long long getsum(int ql, int qr, int v = 1, int l = 1, int r = n)
{
push(v, l, r);
if(l > qr || r < ql) return 0;
if(ql <= l && r <= qr)
return t[v];
int mid = l + r >> 1;
return getsum(ql, qr, v + v, l, mid) +
getsum(ql, qr, v + v + 1, mid + 1, r);
}
void solve(int l, int r, int x)
{
int curr = v[x - 1].fr.fr + (r - v[x - 1].sc.fr);
int curl = v[x - 1].fr.fr;
int idr = getsum(r, r) - 1;
int idl = getsum(l, l) - 1;
if(getsum(l, r) == 0)
{
//cout << l << " " << r << endl;
upd(l, r, x);
//puts("");
return;
}
else
{
if(v[idr].fr.fr + (r - v[idr].sc.fr) < curr)
{
if(idl == -1 || v[idl].fr.fr + (l - v[idl].sc.fr) < curl)
{
upd(l, r, x);
}
}
}
if(l == r)
{
return;
}
int mid = l + r >> 1;
solve(l, mid, x);
solve(mid + 1, r, x);
}
int get(int x, int pos)
{
//cout << x << endl;
if(x == 0) return 0;
int res = v[x - 1].fr.fr;
res += (pos - v[x - 1].sc.fr);
return res;
}
main()
{
cin >> n >> m;
c = m;
for(int i = 1; i <= m; i++)
{
int l, r, x;
cin >> l >> r >> x;
v.pb( mk( mk( x, (r - l + 1) ), mk( l, r ) ) );
}
sort(v.rbegin(), v.rend());
for(int i = 1; i <= m; i++)
{
int l = v[i - 1].sc.fr;
int r = v[i - 1].sc.sc;
solve(l, r, i);
}
//cout << getsum(1, 5) << endl;
//return 0;
for(int i = 1; i <= n; i++)
{
//cout << i << " ";
//get(getsum(i, i), i);
//puts("");
cout << get(getsum(i, i), i) << " ";
}
}
/**
5 2
1 3 2
2 4 6
2 6 7 8 0
6 4
1 2 5
4 4 3
6 6 1
5 6 1
5 6 0 3 1 2
**/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |