# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90917 | YottaByte | Trading (IZhO13_trading) | C++14 | 206 ms | 9360 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 <stdlib.h>
#include <stdio.h>
#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, a[N];
int u[N * 4];
vector < piii > v;
inline void upd(int ql, int qr, int x, int v = 1, int l = 1, int r = n)
{
if(u[v] == r - l + 1) return;
if(l > qr || r < ql) return;
if(l == r && !u[v])
{
a[l] = x;
u[v] = 1;
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);
}
u[v] = u[v + v] + u[v + v + 1];
}
//void solve(int l, int r, int x)
//{
//if(check(l, r) == 0)
//{
//upd(l, r, x);
//}
//if(l == r) return;
//int m = l + r >> 1;
//solve(l, m, x);
//solve(m + 1, r, x);
//}
bool cmp( piii a, piii b )
{
if( a.sc.fr - a.fr < b.sc.fr - b.fr )
{
return true;
}
else if(a.fr == b.fr)
{
if(a.sc.fr < b.sc.fr)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
main()
{
scanf("%d%d", &n, &m);
c = m;
for(int i = 1; i <= m; i++)
{
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
v.pb(mk( x, mk( l, r ) ));
}
sort(v.begin(), v.end(), &cmp);
//int cnt = 1;
//for(auto i : v)
//{
//printf("%d %d %d %d\n", cnt++, i.sc.fr, i.sc.sc, i.fr);
//}
for(int i = 1; i <= m; i++)
{
int l = v[i - 1].sc.fr;
int r = v[i - 1].sc.sc;
int x = v[i - 1].fr;
upd(l, r, i);
}
for(int i = 1; i <= n; i++)
{
int id = a[i] - 1;
if(id >= 0)
printf("%d ", v[id].fr + i - v[id].sc.fr);
else printf("0 ");
}
}
/**
5 2
2 4 6
1 3 2
2 6 7 8 0
----------------------
6 4
1 2 5
4 4 3
5 6 1
6 6 1
5 6 0 3 1 2
----------------------
10 9
7 8 9
10 10 8
9 10 8
10 10 4
6 8 4
3 9 4
4 9 3
1 3 3
4 8 2
3 4 5 5 6 7 9 10 10 9
----------------------
3 4
2 2 4
1 1 4
3 3 1
1 3 0
4 4 2
**/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |