#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
trading.cpp: In function 'void upd(int, int, int, int, int, int)':
trading.cpp:35:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
trading.cpp: At global scope:
trading.cpp:79:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
trading.cpp: In function 'int main()':
trading.cpp:103:7: warning: unused variable 'x' [-Wunused-variable]
int x = v[i - 1].fr;
^
trading.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
trading.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &l, &r, &x);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
560 KB |
Output is correct |
6 |
Correct |
3 ms |
664 KB |
Output is correct |
7 |
Correct |
103 ms |
5084 KB |
Output is correct |
8 |
Correct |
117 ms |
6084 KB |
Output is correct |
9 |
Correct |
116 ms |
6084 KB |
Output is correct |
10 |
Correct |
114 ms |
6084 KB |
Output is correct |
11 |
Correct |
136 ms |
6788 KB |
Output is correct |
12 |
Correct |
138 ms |
6788 KB |
Output is correct |
13 |
Correct |
149 ms |
6788 KB |
Output is correct |
14 |
Correct |
145 ms |
6788 KB |
Output is correct |
15 |
Correct |
165 ms |
6864 KB |
Output is correct |
16 |
Correct |
170 ms |
6968 KB |
Output is correct |
17 |
Correct |
167 ms |
7944 KB |
Output is correct |
18 |
Correct |
179 ms |
8844 KB |
Output is correct |
19 |
Correct |
168 ms |
8844 KB |
Output is correct |
20 |
Correct |
206 ms |
9360 KB |
Output is correct |