Submission #969655

#TimeUsernameProblemLanguageResultExecution timeMemory
969655vjudge1Trading (IZhO13_trading)C++14
0 / 100
1 ms2396 KiB
#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 timeMemoryGrader output
Fetching results...