#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define yes "YES"
#define no "NO"
#define bigg INT_MAX
#define debug(x) cout<<(#x)<<" = " <<x<<endl;
#define all(x) x.begin(),x.end()
#define sz size()
#define nn '\n'
#define mms(x,y) memset(x,y,sizeof(x))
#define forr(i,j,n) for (int i=j; i<n; i++)
#define forn(i,j,n) for (int i=j; i>n; i--)
#define fi first
#define se second
#define la "LA"
#define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i];
#define pii pair<int,int>
signed main()
{
// #ifndef LOCAL
// freopen("lifeguards.in","r",stdin);
// freopen("lifeguards.out","w", stdout);
// #endif
fast
int n,m;
cin>>n >>m;
vector<int> a[n+1];vector<int> b[n+1];
int ans[n+1]={ };
forr(i,0,m)
{
int x,y,z;
cin>>x >>y >>z;
x--;
// y--;
a[x].pb(z-x);
b[y].pb(z-x);
}
map<int,int> mp;
priority_queue<int> q;
map<int,pii> k;
// 5 . . 6
forr(i,0,n)
{
for(auto j:a[i])
{
q.push(j);
//if (j<0) mp[j]++;
}
for(auto j:b[i])
{
// if (j>0) q.push(j);
mp[j]++;
}
while(!q.empty() && mp[q.top()]) { mp[q.top()]--;
q.pop();
}
if (!q.empty()) ans[i]=q.top()+i;
}
forr(i,0,n) cout<<ans[i]<<' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
720 KB |
Output is correct |
7 |
Correct |
130 ms |
26800 KB |
Output is correct |
8 |
Correct |
151 ms |
30772 KB |
Output is correct |
9 |
Correct |
166 ms |
30716 KB |
Output is correct |
10 |
Correct |
159 ms |
33324 KB |
Output is correct |
11 |
Correct |
172 ms |
35668 KB |
Output is correct |
12 |
Correct |
186 ms |
38324 KB |
Output is correct |
13 |
Correct |
193 ms |
38672 KB |
Output is correct |
14 |
Correct |
240 ms |
40696 KB |
Output is correct |
15 |
Correct |
258 ms |
44088 KB |
Output is correct |
16 |
Correct |
258 ms |
44852 KB |
Output is correct |
17 |
Correct |
260 ms |
44824 KB |
Output is correct |
18 |
Correct |
251 ms |
47536 KB |
Output is correct |
19 |
Correct |
294 ms |
48456 KB |
Output is correct |
20 |
Correct |
324 ms |
52924 KB |
Output is correct |