# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20249 | petil | Trading (IZhO13_trading) | C++14 | 501 ms | 64 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 <cstdio>
#include <set>
#include <vector>
using namespace std;
int n, m;
struct info{
int x, L, idx;
info(int a, int b, int c) : x(a), L(b), idx(c){}
bool operator<(const info &i)const{
if (x == i.x){
if (idx == i.idx)return L < i.L;
return idx < i.idx;
}
return x > i.x;
}
};
multiset < info > s;
vector<info> st[300003], ed[300003];
int ans[300003];
int main(){
scanf("%d %d", &n, &m);
for (int le, ri, x, i = 1; i <= m; i++){
scanf("%d %d %d", &le, &ri, &x);
st[le].push_back(info(x-le, le, i));
ed[ri].push_back(info(x-le, le, i));
}
for (int day = 1; day <= n; day++){
for (int i = 0; i < st[day].size(); i++)
s.insert(info(st[day][i].x, st[day][i].L, st[day][i].idx));
if (s.empty())ans[day] = 0;
else{
ans[day] = s.begin()->x + day;
}
for (int i = 0; i < ed[day].size(); i++){
auto it = s.find(ed[day][i]);
s.erase(it);
}
}
for (int i = 1; i <= n; i++)printf("%d ", ans[i]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |