# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
947860 | vjudge306 | Trading (IZhO13_trading) | C++17 | 1 ms | 348 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>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nn "\n"
#define x_x ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define intt int _; cin >> _; while (_--)
#define emp push_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define ld long double
#define A first
#define B second
typedef long long ll;
const ld eps = 1e-27;
// diff between decimals 0.000000001 mt19937 mt(time(nullptr));
struct in {
int x; int i; int v;
};
struct com {
bool operator()(const pair<int,int>&a, const pair<int,int>&b) const {
int x=max(a.B,b.B); int i=a.A+(x-a.B), j=b.A+(x-b.B);
if (i>j) return a.A>(b.A*-1);
return b.A>(a.A*-1);
}
};
int main() {
x_x
int n=0,m=0; cin>>n>>m; vector<in>ar[n]; pair<int,int>nm[m];
for (int i=0, a, b, c; i<m; i++)
cin>>a>>b>>c, ar[a-1].emp({1,i,c}), ar[b-1].emp({0,i,c}), nm[i]={a-1,b-1};
set<pair<int,int>>s;
for(int i=0; i<n; i++) {
int mx=0;
if(!s.empty()) {auto it=s.end(); --it;
pair<int,int>x=*it; s.erase(it);
mx=x.A+(i-nm[x.B].A); nm[x.B].A=i; s.insert({mx, x.B});
}
if(!ar[i].empty()) {
for (auto j:ar[i]) {
if (j.x) {
mx=max(mx, j.v); s.insert({j.v, j.i});
}
else {
s.erase(s.lower_bound({j.v, j.i}));
}
}
}
cout<<mx<<' ';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |