# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969662 | SeenSiravit | Trading (IZhO13_trading) | C++14 | 1 ms | 2396 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<bits/stdc++.h>
#define ll long long
#define ar array
using namespace std;
const int mxN = 3e5 + 5;
int n,m;
ar<int,3> t[mxN];
ll ans[mxN];
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin>> n >> m;
for(int i=1;i<=m;i++){
cin>> t[i][1] >> t[i][0] >> t[i][2];
t[i][2] = t[i][2] - t[i][1];
}
sort(t+1 , t+1+m);
// for(int i=1;i<=m;i++) printf("%d %d %d\n",t[i][1] , t[i][0] , t[i][2]);
int idx = 1;
deque<int> dq;
for(int i=1;i<=n;i++){
// clear past data
while(!dq.empty() && t[dq.front()][0]<i) dq.pop_front();
// add new data
while(idx<=m && t[idx][1]<=i){
while(!dq.empty() && t[dq.back()][2] <= t[idx][2]) dq.pop_back();
dq.push_back(idx);
idx++;
}
ans[i] = (dq.empty() ? 0 : t[dq.front()][2] + i);
}
for(int i=1;i<=n;i++) cout<< ans[i] << " ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |