This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#warning Check FastIO
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#endif
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <random>
#include <chrono>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
#define vll vector<ll>
#define sll set<ll>
#define vstr vector<string>
#define ll long long
#define ld long double
#define supra main
#define pb push_back
#define add insert
#define rall(x) rbegin(x),rend(x)
#define all(x) (x).begin(),(x).end()
#define I ios_base::sync_with_stdio(false);
#define Hear cin.tie(NULL);
#define Shots cout.tie(NULL);
#define Ratatatata
#define bits_on(a) (__builtin_popcountll(a))
#define mx_pw2(a) (__builtin_ctzll(a))
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
#define SHUFFLE(v) shuffle(all(v), RNG);
const ll inf=LLONG_MAX;
void input(vll& a)
{
for(auto& i:a)
cin>>i;
}
void pyn(bool a)
{
cout<<(a?"YES":"NO")<<endl;
}
ll powmod(ll a,ll b,ll modulo)
{
if(b==0){
return 1;
}
ll temp=powmod(a,b/2,modulo);
if(b%2==0){
return (temp*temp)%modulo;
}
else{
return (a*((temp*temp)%modulo))%modulo;
}
}
bool Prime(ll n){
for (ll i = 2; i*i <= n; i++)
if (n % i == 0)
return false;
return (n>1);
}
// struct rider
// {
// int index=i;
// int speed[3];
// int position=0;
// int boost_time_left=0;
// };
const int N=2e4+100;
int def[N][3];
bool acel[400];
int cnt[400];
void solve()
{
ll n;
cin>>n;
set<vll> riders;
for(int i=0;i<n;i++)
{
cin>>def[i][0]>>def[i][1]>>def[i][2];
cnt[0]++;
riders.insert({def[i][0],0,0,i});
}
ll m;
cin>>m;
for(int j=0;j<m;j++)
{
ll x;
cin>>x;
acel[x]=1;
}
vll ans(n+2);
for(int i=0;i<n;i++){
ans[i]=50*301;
}
for(ll time=0;time<=(50*300);time++)
{
vll pos_to_ch;
while(riders.size()>0)
{
auto it=*begin(riders);
it[1]*=-1;
// Time , position , boost, index
// 0 1 2 3
if(it[0]==time)
{
riders.erase(begin(riders));
if(it[1]==300)
{continue;}
pos_to_ch.push_back(it[1]);
if(it[2]>0)
{
it[1]++;
it[2]--;
it[0]++;
if(it[1]==300)
ans[it[3]]=time;
it[1]*=-1;
riders.insert(it);
continue;
}
ll new_position=it[1]+1;
ll track=2;
if(new_position<100)
{
track=0;
}
else if(new_position<200)
{
track=1;
}
if(new_position==300)
ans[it[3]]=time;
if(acel[new_position])
{
ll sm=0;
for(int j=300;j>new_position;j--)
sm+=cnt[j];
sm%=20;
it[2]=sm;
}
ll nxt_time;
if(it[2]>0)
{
it[2]--;
nxt_time=it[0]+1;
}
else
{
nxt_time=it[0]+def[it[3]][track];
}
it[0]=nxt_time;
it[1]++;
it[1]*=-1;
riders.insert(it);
}
else
{
break;
}
}
for(auto j:pos_to_ch)
{
cnt[j]--;
cnt[j+1]++;
}
pos_to_ch.clear();
}
for(int i=0;i<n;i++)
cout<<ans[i]<<endl;
}
int supra(){
I Hear Shots Ratatatata
ll tqwertyuiop=1;
for(int tp=1;tp<=tqwertyuiop;tp++)
{
// cout<<"Case #"<<tp<<": ";
solve();
}
return 0;
}
/*
Bro use only in a emergency
this is kind of hacking
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
*/
Compilation message (stderr)
segway.cpp:1:2: warning: #warning Check FastIO [-Wcpp]
1 | #warning Check FastIO
| ^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |