#include <bits/stdc++.h>
#define DIM 300010
using namespace std;
struct eventt{
int poz,tip,idx;
};
vector <eventt> events;
multiset <int> s;
struct idk{
int x,y,val;
} v[DIM];
inline int cmp (eventt a, eventt b){
return a.poz < b.poz;
}
int n,m,i,x,y,val;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>m;
for (i=1;i<=m;i++){
cin>>x>>y>>val;
events.push_back({x,1,i});
events.push_back({y+1,-1,i});
v[i] = {x,y,val};
}
sort (events.begin(),events.end(),cmp);
int pos = 0;
for (i=1;i<=n;i++){
while (pos < events.size() && events[pos].poz == i){
int idx = events[pos].idx;
if (events[pos].tip == 1)
s.insert(v[idx].val - v[idx].x);
else s.erase(s.find(v[idx].val - v[idx].x));
pos++;
}
if (s.empty())
cout<<0<<" ";
else cout<<i + *s.rbegin()<<" ";
}
return 0;
}
Compilation message
trading.cpp: In function 'int main()':
trading.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<eventt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | while (pos < events.size() && events[pos].poz == i){
| ~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
4 ms |
620 KB |
Output is correct |
7 |
Correct |
292 ms |
12148 KB |
Output is correct |
8 |
Correct |
291 ms |
12752 KB |
Output is correct |
9 |
Correct |
311 ms |
14168 KB |
Output is correct |
10 |
Correct |
351 ms |
16592 KB |
Output is correct |
11 |
Correct |
323 ms |
14416 KB |
Output is correct |
12 |
Correct |
445 ms |
18640 KB |
Output is correct |
13 |
Correct |
398 ms |
16336 KB |
Output is correct |
14 |
Correct |
416 ms |
18384 KB |
Output is correct |
15 |
Correct |
520 ms |
19536 KB |
Output is correct |
16 |
Correct |
493 ms |
18928 KB |
Output is correct |
17 |
Correct |
470 ms |
19916 KB |
Output is correct |
18 |
Correct |
517 ms |
22848 KB |
Output is correct |
19 |
Correct |
503 ms |
20304 KB |
Output is correct |
20 |
Correct |
556 ms |
22492 KB |
Output is correct |