#include<bits/stdc++.h> #define TLE ios::sync_with_stdio(0),cin.tie(0) #define endl "\n" #define FILE "a" #define pb push_back #define gg exit(0); #define rt return; #define bd cout<<"debug"<<endl; #define db(x) cout<<#x<<':'<<x<<endl; #define dbb(i,a) cout<<#i<<':'<<i<<' '<<#a<<':'<<a<<' '<<endl; #define dbbb(i,a,b) cout<<#i<<':'<<i<<' '<<#a<<':'<<a<<' '<<#b<<':'<<b<<endl; #define TIME cout<<"RuningTime: "<<clock()<<"ms\n"; #define YES cout<<"YES"<<endl; #define Yes cout<<"Yes"<<endl; #define NO cout<<"NO"<<endl; #define No cout<<"No"<<endl; #define None cout<<-1<<endl; #define el cout<<endl; #define x first #define y second #define V vector #define fo(i,j,n) for(int i = j;i<=n;i++) #define of(i,n,j) for(int i = n;i>=j;i--) #define fe(i,u) for(int i = h[u];~i;i=ne[i]) #define all(a) a.begin(),a.end() #define alll(a) a.begin()+1,a.end() #define ms(a,b) memset(a, b, sizeof(a)); #define tr_len(u) (tr[u].r - tr[u].l + 1) #define tr_mid (tr[u].l + tr[u].r >> 1) #define ul (u<<1) #define ur (u<<1|1) #define lowbit(x) (x&-x) #define gcd(a,b) __gcd(a,b) #define CLAP 11243 using namespace std; void clapping() { #if CLAP == 1 srand(time(NULL)+rand()); freopen("a.in","r",stdin); freopen("a.out","w",stdout); // freopen("a.in","w",stdout); #endif } template<class T>inline void read(T &res) { char c;T flag = 1; while((c = getchar()) < '0' || c > '9') if(c == '-') flag = -1;res = c - '0'; while((c=getchar())>='0'&&c<='9')res=(res<<1)+(res<<3)+(c^48);res*=flag; } typedef pair<int,int> pii; typedef pair<long,long>pll; typedef long long ll; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fll; const double eps = 1e-8; int dy[] = {1,0,-1,0,1,1,-1,-1}; int dx[] = {0,1,0,-1,1,-1,1,-1}; ll qmi(ll a,ll b) {int res = 1;for(;b;b>>=1,a = a * a ) {if(b&1) res = res * a;}return res;} template<class T> T exgcd(T a,T b,T &x,T &y) { if(b == 0) {x = 1;y = 0;return a;} ll d = gcd_ed(b,a%b,y,x); y = y - a / b * x; return d; } template<class T> T qmul(T a,T b,T p) { T res = 0; for(;b;b >>= 1,a = (a + a) % p) { res = (res + a) % p; } return res; } /*文档区 */ void AC() { // // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`---'\___ // .' \\| |// '. // / \\||| : |||// \ // / _||||| -:- |||||- \ // | | \\\ - /// | | // | \_| ''\---/'' |_/ | // \ .-\__ '-' ___/-. / // ___'. .' /--.--\ `. .'___ // ."" '< `.___\_<|>_/___.' >' "". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `_. \_ __\ /__ _/ .-` / / // =====`-.____`.___ \_____/___.-`___.-'===== // 佛祖保佑, 永无bug; } //-------------------------代码---------------------------- #define int ll const int N = 2e5+10; int n,m,k; struct node { int p,v,t,id; }p[N]; node q[N]; int l[N],r[N]; bool cmp1(node a,node b) { return a.id < b.id; } bool cmp2(node a,node b) { return a.p < b.p; } bool check(int t) { fo(i,1,n) { p[i].id = i; q[i] = p[i]; } fo(i,1,n) { q[i].p = q[i].p + q[i].v * t; } sort(q+1,q+1+n,cmp2); for(int i = 1;i<=n;) { if(q[i].id == i) { i ++ ; continue; } int j = q[i].id; int idx = i + 1; while(idx <= n && idx <= j) { j = max(j,q[i].id); if(q[idx].t != q[i].t) return false; idx ++ ; } i = max(i+1,j); } return 1; } void solve() { // cin>>n>>m; cin>>n>>k; fo(i,1,n) { int pp,v,t;cin>>pp>>v>>t; p[i] = {pp,v,t,i}; } sort(p+1,p+1+n,cmp2); fo(i,1,n) { if(p[i].t == p[i-1].t) { l[i] = l[i-1]; } else { l[i] = i; } } of(i,n,1) { if(p[i].t == p[i+1].t) { r[i] = r[i+1] } } int l = 1,r = 1e10; while(l < r) { int mid = l + r + 1>> 1; if(check(mid)) l = mid; else r = mid - 1; } if(l == 2e9 ) { cout<<-1<<endl; } else { cout<<l<<endl; } } void main_init() {} signed main(){ AC();clapping();TLE; cout<<fixed<<setprecision(12); main_init(); // while(cin>>n,n) // while(cin>>n>>m,n,m) // int t;cin>>t;while(t -- ) solve(); // {solve(); } return 0; } /*样例区 */ //------------------------------------------------------------
标签:return,int,res,ll,上海,tr,2021,define From: https://www.cnblogs.com/er007/p/16647752.html