제출 #1341117

#제출 시각아이디문제언어결과실행 시간메모리
1341117JuanJLMarathon Race 2 (JOI24_ho_t3)C++20
7 / 100
1 ms344 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define fst first
#define snd second
#define pb push_back
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define forn(i,a,b) for(int i = a; i<b; i++)
#define mset(a,v) memset(a,v,sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template< typename T >
using iset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll actualres(multiset<ll> &s){
	ll mini = *s.begin();
	ll maxi = *(--s.end());
	ll res = maxi-mini;
	return res;
}

const int MAXN = 200000+5;

vector<pair<ll,ll>> adj[MAXN];

ll n;
bool vis[MAXN];

vector<ll> dijkstra(ll ini){
	vector<ll> dist(n,10000000000000000);

	dist[ini]=0;
	priority_queue<pair<ll,ll>> pq; pq.push({0,ini});

	while(!pq.empty()){
		ll nd = pq.top().snd;
		ll cost = pq.top().fst*-1;
		pq.pop();
		vis[nd]=true;
		

		if(dist[nd]!=cost) continue;

		for(auto i:adj[nd]){
			if(dist[i.fst]==-1 || dist[i.fst]>cost+i.snd){
				dist[i.fst]=cost+i.snd;
				pq.push({dist[i.fst]*-1,i.fst});
			}
		}
	}

	return dist;
}

int main(){ FIN;
	ll l;
	cin>>n>>l;
	vector<ll> x(n); forn(i,0,n) cin>>x[i];

	sort(ALL(x));

	ll q; cin>>q;
	while(q--){
		ll s,g,t; cin>>s>>g>>t;

		ll cost = 0;
		//Paso ( ir a left , recolectar hasta g(no incluido) , ir a right , recolectar hasta g incluido , ir a g)
		if(s<=g){// s to left , left to right , right to g
			cost = 0;
			ll pos = s;
			ll acum = 0;

			// ir a left
			cost+=abs(pos-x[0]);
			pos=x[0];

			// recolectar hasta g(no incluido)
			forn(i,0,n){
				if(x[i]>=g)	break;
				cost+=abs(pos-x[i])*(1+acum);
				pos=x[i];
				acum++;
				cost++;
			}

			//ir a right
			cost+=abs(pos-x.back())*(1+acum);
			pos=x.back();

			//recolectar hasta g incluido
			for(int i = n-1; i>=0; i--){
				if(x[i]<g) break;
				cost+=abs(pos-x[i])*(1+acum);
				pos=x[i];
				acum++;
				cost++;
			}
			
			// ir a g
			cost+=abs(pos-g)*(1+acum);
			pos=g;

			//cout<<cost<<'\n';
		}else{
		// g to left , left to right , right to s
				cost = 0;
			ll pos = s;
			ll acum = 0;

			// ir a right
			cost+=abs(pos-x.back());
			pos=x.back();

			// recolectar hasta g(no incluido)
			for(int i = n-1; i>=0; i--){
				if(x[i]<=g)	break;
				cost+=abs(pos-x[i])*(1+acum);
				pos=x[i];
				acum++;
				cost++;
			}

			//ir a left
			cost+=abs(pos-x[0])*(1+acum);
			pos=x[0];

			//recolectar hasta g incluido
			forn(i,0,n){
				if(x[i]>g) break;
				cost+=abs(pos-x[i])*(1+acum);
				pos=x[i];
				acum++;
				cost++;
			}
			
			// ir a g
			cost+=abs(pos-g)*(1+acum);
			pos=g;

			//cout<<cost<<'\n';
		}
		if(cost<=t) cout<<"Yes\n";
		else cout<<"No\n";
		
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...