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>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
#define sz(x) ll(x.size())
#define N 100015
#define base 1000000
#define M ll(1e9+7)
#define F first
#define S second
#define pb push_back
#define in insert
#define eb emplace_back
#define ed "\n"
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//
int t[N], pos[15005][305], been[305][305], dob[305], koler[15005][305];
bool booster[305];
void upd(int v, int val) {for (; v < N; v = (v | (v + 1))) t[v] += val;}
int get(int v) {int res = 0; for (; v >= 0; v = (v & (v + 1)) - 1) res += t[v]; return res;}
int main()
{
    //freopen("input.txt","r",stdin);
   //  freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    int m;
    cin >> m;
//    if (m == 0)
//    {
//        for (int i = 0; i < n; i++) cout << (a[i] + b[i] + c[i]) * 100 << endl;
//
//        exit(0);
//    }
//    else if (m == 1)
//    {
//        int t;
//
//        cin >> t;
//
//        int when[n];
//
//        for (int i = 0; i < n; i++)
//        {
//            if (t <= 100) when[i] = t * a[i];
//              else if (t <= 200) when[i] = 100 * a[i] + (t - 100) * b[i];
//                else when[i] = 100 * (a[i] + b[i]) + (t - 200) * c[i];
//
//            upd(when[i], 1);
//        }
//
//        for (int i = 0; i < n; i++)
//        {
//            int tp = get(when[i] - 1) % 20;
//
//            int ans = when[i] + min(tp, 300 - t);
//
//            int tr = t + tp;
//
//            if (tr <= 100) ans += (b[i] + c[i]) * 100 + a[i] * (100 - tr);
//              else if (tr <= 200) ans += c[i] * 100 + b[i] * (200 - tr);
//                else if (tr <= 300) ans += c[i] * (300 - tr);
//
//            cout << ans << '\n';
//        }
//    }
//    else
//    {
        for (; m > 0; m--) {int t; cin >> t; booster[t] = 1;}
        int ans[n];
        for (int i = 1; i <= 15000; i++)
        {
            vector <int> vr; vr.clear();
            vector <int> check; check.clear();
            vr.pb(1e9);
            for (int j = 0; j < n; j++)
            {
                int lst = pos[i - 1][j];
                if (lst == 300) {pos[i][j] = pos[i - 1][j]; vr.pb(lst); continue;}
                int spd = 0;
                bool f = 0;
                if (dob[j] != 0) {f = 1; spd = 1; dob[j]--;}
                  else if (lst < 100) spd = a[j];
                    else if (lst < 200) spd = b[j];
                      else spd = c[j];
                if (i - been[j][lst] >= spd)
                {
                    been[j][lst + 1] = i;
                    pos[i][j] = lst + 1;
                    koler[i][lst + 1]++;
                    if (!f && booster[pos[i][j]]) check.pb(j);
                    if (lst + 1 == 300) ans[j] = i;
                } else pos[i][j] = lst;
                vr.pb(pos[i][j]);
            }
            sort(vr.begin(), vr.end());
            for (auto it : check)
            {
                int kol = sz(vr) - (lower_bound(vr.begin(), vr.end(), pos[i][it]) - vr.begin()) - 1 - koler[i][pos[i][it]];
                dob[it] = kol % 20;
            }
        }
        for (int i = 0; i < n; i++) cout << ans[i] << '\n';
//    }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |