# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969655 | vjudge1 | 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];
ll cal(int vil , int idx_t){
return t[idx_t][2] + (vil - t[idx_t][1]);
}
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];
}
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){
ll new_val = cal(i , idx);
while(!dq.empty() && cal(i , dq.back()) < new_val) dq.pop_back();
dq.push_back(idx);
idx++;
}
ans[i] = (dq.empty() ? 0 : cal(i , dq.front()));
}
for(int i=1;i<=n;i++) cout<< ans[i] << " ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |