Problem:
F - Acceleration of Network
インターネットと言う広大な海は少しずつ黒く塗りつぶされていった。
ボットの反乱、DDOS攻撃の嵐、ウィルスの蔓延、
何度も何度も繰り返されたクラッカーとの戦争で、人もインターネットもボロボロになった。
人の手では、インターネットはどうにもならない。
だから人は、とんでもない時間をかけて
インターネットを復旧できる「少女」を造った。
少女は、インターネットの手当をはじめた。
果てしなく広いインターネットの世界をどうにかしようと頑張った。
まだ少女ひとりでは撚り対線を織る事くらいしかできないけど、
長い長い時がすぎてインターネットが少し復旧すれば、
みんなと一緒に頑張れるだろうという期待をこめて。
問題文
少女はかつてインターネットに存在した
N
個のサービスを復旧するために日々頑張っている．
現在を 0 日目とする．
インターネットがどの程度復旧しているかを
復旧度
という指標で表し，現在の復旧度は 0 であるとする．
少女は毎日作業をし，復旧度を 1 日につき 1 ずつ上げていく．
任意のまだ復旧していないサービス
i
は，復旧度が
w
i
以上になると自動的に復旧する．
サービス
i
が復旧すると，みんなが手伝ってくれることにより，復旧した次の日から
x
i
日間だけ作業がはかどり，復旧度の増加が加速する．
サービスには 3 つの種類があり，種類によって復旧度がどの程度増加するのかが異なる．
サービスの種類を
0, 1, 2
の番号で表すとする．
サービス
i
の種類を t
i
(∈ {0, 1, 2}) とすると，
サービス
i
が復旧してから
d-1
日目から
d
日目にかけて
(1 ≤ d ≤ x
i
)
，
t
i
=0
の場合は
1
，
t
i
=1
の場合は
d
，
そして
t
i
=2
の場合は
d
2
だけ，少女の作業とは別に復旧度が増加する．
また，同時に複数のサービスが復旧している場合，それぞれのサービスは独立に並行して復旧度を増加させる．
少女はサービスが復旧するまでにとんでもない時間がかかると思ったので，現在から何日目にサービスが復旧するか調べることにした．
またある日にち
y
j
に復旧度がいくらになっているかも気になったので，それも
Q
日分だけ調べることにした．
入力形式
入力は以下の形式で与えられる．
N
Q
w
1
t
1
x
1
...
w
N
t
N
x
N
y
1
...
y
Q
出力形式
最初に
N
行出力し，
i
行目にはサービス
i
の復旧する日にちを出力せよ．次に
Q
行出力し，
j
行目には
y
j
日目に復旧度がいくらになっているかを出力せよ．
サービスが復旧する日にちが
3,652,425
を超える場合は
Many years later
と出力せよ．
制約
0 ≤ N ≤ 10
5
1 ≤ Q ≤ 10
5
0 ≤ w
i
< 2
60
w
i
≤ w
i+1
(1 ≤ i < N)
t
i
∈ {0, 1, 2}
1 ≤ x
i
≤ 10
4
0 ≤ y
j
≤ 3,652,425
y
j
< y
j+1
(1 ≤ j < Q)
入力値はすべて整数である．
この問題の判定には，15 点分のテストケースのグループが設定されている．このグループに含まれるテストケースは上記の制約に加えて下記の制約も満たす．
N,Q,w
i
,y
j
≤ 1,000
注意
0 日目の復旧度は 0 である．
w
i
=0
の時，サービス
i
は 0 日目に復旧する．
入出力例
入力例1
3 11
1 0 2
4 1 3
7 2 4
0
1
2
3
4
5
6
7
8
9
10
出力例1
1
3
4
0
1
3
5
7
11
19
29
46
47
48
入力例2
5 5
10000 0 20
10000 1 30
10000 0 40
10000 2 70
30000 2 10000
5000
10000
15000
20000
25000
出力例2
10000
10000
10000
10000
10039
5000
10000
40711690801
329498273301
333383477320
入力例3
2 2
3652425 0 1
3652426 2 10000
3652424
3652425
出力例3
3652425
Many years later
3652424
3652425
2つ目のサービスは復旧する日にちが
3,652,425
日を超えているので
Many years later
と出力している．
Writer : 森槙悟
Tester : 田村和範

Submitted solutions:

code_snippet: // AOJ #2411 Acceleration of Network
// 2025.3.17

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

ll Cinll() {  // 整数の入力
	ll n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(ll n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

void Couts(const string &s) {
    for (char c : s) pc(c);
    pc('\n');
}

const int DMAX = 3652425;
struct TBL { ll weight; int type, x, triggerDay; };
TBL tbl[100005];
ll levelHistory[DMAX+5];

int main() {
    int n = Cin(), Q = Cin();

    for (int i = 0; i < n; ++i) {
        tbl[i].weight = Cinll(), tbl[i].type = Cin(), tbl[i].x = Cin();
        tbl[i].triggerDay = -1;
    }

    ll speed = 1;
    ll acc = 0;
    ll extraAcc = 0;
    ll level = -1;

    map<int, ll> speedMap;
    map<int, ll> accMap;
    map<int, ll> extraAccMap;

    int serviceIndex = 0;
    for (int day = 0; day <= DMAX; ++day) {
        acc += extraAcc;
        speed += acc;
        level += speed;
        levelHistory[day] = level;

        while (serviceIndex < n && tbl[serviceIndex].weight <= level) {
            tbl[serviceIndex].triggerDay = day;
            int x = tbl[serviceIndex].x;
            int type = tbl[serviceIndex].type;
            int futureDay = day + x;

            if (type == 0) {
                speed++;
                speedMap[futureDay] -= 1;
            } else if (type == 1) {
                acc++;
                accMap[futureDay] -= 1;
                speedMap[futureDay] -= x;
            } else {
                acc--;
                extraAcc += 2;
                extraAccMap[futureDay] -= 2;
                accMap[futureDay] -= (2 * x - 1);
                speedMap[futureDay] -= (x * x);
            }
            serviceIndex++;
        }

        if (extraAccMap.count(day)) {
            extraAcc += extraAccMap[day];
            extraAccMap.erase(day);
        }
        if (accMap.count(day)) {
            acc += accMap[day];
            accMap.erase(day);
        }
        if (speedMap.count(day)) {
            speed += speedMap[day];
            speedMap.erase(day);
        }
    }
    for (int i = 0; i < n; ++i) {
        if (tbl[i].triggerDay == -1) Couts("Many years later");
        else Cout(tbl[i].triggerDay);
    }
    while (Q--) Cout(levelHistory[Cin()]);
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 35528
final_rank: 3

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-8, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 998244353 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  if(x == 0) return 0;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
template<typename T> 
struct BIT{
  int N;
  std::vector<T> node;
  BIT(){}
  BIT(int n){
    N = n;
    node.resize(N+10);
  }
  void build(int n) {
    N = n;
    node.resize(N+10);
  }
  /* a: 1-indexed */
  void add(int a, T x){
    for(int i=a; i<(int)node.size(); i += i & -i) node[i] += x;
  }

  /* [1, a] */
  T sum(int a){
    T res = 0;
    for(int x=a; x>0; x -= x & -x) res += node[x];
    return res;
  }

  /* [l, r] */
  T rangesum(int l, int r){
    return sum(r) - sum(l-1);
  }

  /* 
    a1+a2+...+aw >= valとなるような最小のwを返す
    @verify https://codeforces.com/contest/992/problem/E
  */
  int lower_bound(T val) {
    if(val < 0) return 0;

    int res = 0;
    int n = 1; 
    while (n < N) n *= 2;

    T tv=0;
    for (int k = n; k > 0; k /= 2) {
      if(res + k < N && node[res + k] < val){
        val -= node[res+k];
        res += k;
      }
    }
    return res+1; 
  }
};
struct UnionFind{
  std::vector<int> par;
  std::vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) std::swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
struct RollingHash{

    using ull = unsigned long long;
    const ull mod = (1ULL << 61) - 1;
    const ull MASK30 = (1ULL << 30) - 1;
    const ull MASK31 = (1ULL << 31) - 1;

    const ull MASK61 = mod;

    ull base;
    int n;
    vector<ull> hash, pow;

    RollingHash(const string &s)
    {
        random_device rnd;
        mt19937_64 mt(rnd());
        base = 1001;
        
        n = (int)s.size();
        hash.assign(n+1, 0);
        pow.assign(n+1, 1);
        
        for(int i=0; i<n; i++){
            hash[i+1] = calc_mod(mul(hash[i], base) + s[i]);
            pow[i+1] = calc_mod(mul(pow[i], base));
        }
    }

    ull calc_mod(ull x){
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if(res >= mod) res -= mod;
        return res;
    }

    ull mul(ull a, ull b){
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & MASK30;
        return calc_mod(au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    //[l,r)のハッシュ値
    inline ull get(int l, int r){
        ull res = calc_mod(hash[r] + mod*3-mul(hash[l], pow[r-l]));
        return res;
    }
    //string tのハッシュ値
    inline ull get(string t){
        ull res = 0;
        for(int i=0; i<t.size(); i++){
            res = calc_mod(mul(res, base)+t[i]);
        }
        return res;
    }
    //string s中のtの数をカウント
    inline int count(string t) {
        if(t.size() > n) return 0;
        auto hs = get(t);
        int res = 0;
        for(int i=0; i<n-t.size()+1; i++){
            if(get(i, i+t.size()) == hs) res++; 
        }
        return res;
    }

    /* 
        concat 
        @verify https://codeforces.com/problemset/problem/514/C
    */
    inline ull concat(ull h1, ull h2, int h2len){
      return calc_mod(h2 + mul(h1, pow[h2len]));
    }

    // LCPを求める S[a:] T[b:]
    inline int LCP(int a, int b){
        int len = min((int)hash.size()-a, (int)hash.size()-b);
        
        int lb = -1, ub = len;
        while(ub-lb>1){
            int mid = (lb+ub)/2;

            if(get(a, a+mid) == get(b, b+mid)) lb = mid;
            else ub = mid;
        }
        return lb;
    }
};

int main() {  
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  
  int n, q; cin >> n >> q;
  
  vector<ll> ans(n,-1), ans2(q);
  vector<ll> w(n), t(n), x(n);
  REP(i,n) cin >> w[i] >> t[i] >> x[i];
  vector<ll> y(q);
  REP(i,q) cin >> y[i];
  int ptr1 = 0, ptr2 = 0;
  ll t0 = 0, t1 = 0, t2 = 0, t3 = 0;
  ll sum0 = 0, sum1 = 0, sum2 = 0;
  ll asum = 0;
  set<pair<int, int>> st;
  for(int i=0; i<=3652425; i++) {
    if(ptr2 < q && y[ptr2] == i) {
      ans2[ptr2] = asum;
      ptr2++;
    }
    
    while(ptr1 < n && w[ptr1] <= asum) {
      ans[ptr1] = i;
      st.insert({i+x[ptr1]-1, ptr1});
      if(t[ptr1] == 0) t0++;
      else if(t[ptr1] == 1) t1++;
      else t2++;

      ptr1++;
    }
    while(st.size() && st.begin()->first < i) {
      if(t[st.begin()->second] == 0) {
        t0--;
      }else if(t[st.begin()->second] == 1) {
        t1--;
        sum1 -= x[st.begin()->second];
      }else{
        sum2 -= x[st.begin()->second]*x[st.begin()->second];
        t3 -= x[st.begin()->second];
        t2--;
      }
      st.erase(st.begin());
    }
    sum1 += t1;
    sum2 += 2*t3 + t2;
    t3 += t2;
    asum += 1 + t0 + sum1 + sum2;
    asum = min(asum, (1LL<<60));
  }
  REP(i,n) {
    if(ans[i] == -1) cout << "Many years later" << '\n';
    else cout << ans[i] << '\n';
  }
  REP(i,q) {
    cout << ans2[i] << '\n';
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 11772
final_rank: 1

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define MAX 3652425
#define NUM 100005

struct Info{
	bool operator<(const struct Info &arg) const{

		return w < arg.w;
	}
	ll w,t,x,index;
};

struct Data{
	Data(ll arg_finish_day,ll arg_minus_A,ll arg_minus_B,ll arg_minus_C){
		finish_day = arg_finish_day;
		minus_A = arg_minus_A;
		minus_B = arg_minus_B;
		minus_C = arg_minus_C;
	}
	bool operator<(const struct Data &arg) const{

		return finish_day > arg.finish_day; //終了日の昇順(PQ)
	}

	ll finish_day,minus_A,minus_B,minus_C;
};

ll N,num_query;
ll A,B,C;
ll REC_DAY[NUM],Y[NUM],value[MAX+1];
Info info[NUM];


int main(){

	scanf("%lld %lld",&N,&num_query);

	for(int i = 0; i < N; i++){

		REC_DAY[i] = BIG_NUM;
	}

	for(int i = 0; i < N; i++){

		scanf("%lld %lld %lld",&info[i].w,&info[i].t,&info[i].x);
		info[i].index = i;
	}

	sort(info,info+N);

	for(int i = 0; i < num_query; i++){

		scanf("%lld",&Y[i]);
	}

	ll recovery = 0,num_recover = 0;
	ll L,R,mid,max_index;
	A = 0, B = 0, C = 0;

	priority_queue<Data> Q;

	for(ll day = 0; day <= MAX; day++){

		//終了情報を反映
		while(Q.empty() == false && Q.top().finish_day == day){

			A -= Q.top().minus_A;
			B -= Q.top().minus_B;
			C -= Q.top().minus_C;
			Q.pop();
		}

		recovery += A*day*day + B*day + C;
		value[day] = recovery;

		if(num_recover < N){

			//二分探索で、新たに復旧したサービスを調べる
			L = num_recover,R = N-1,mid = (L+R)/2;
			max_index = num_recover-1;

			while(L <= R){

				if(info[mid].w <= recovery){

					max_index = mid;
					L = mid+1;
				}else{

					R = mid-1;
				}
				mid = (L+R)/2;
			}

			for(int i = num_recover; i <= max_index; i++){

				REC_DAY[info[i].index] = day;

				switch(info[i].t){
				case 0:
					C += 1;
					Q.push(Data(day+1+info[i].x,0,0,1));
					break;
				case 1:
					B += 1;
					C -= day;
					Q.push(Data(day+1+info[i].x,0,1,-day));
					break;
				case 2:
					A += 1;
					B -= 2*day;
					C += day*day;
					Q.push(Data(day+1+info[i].x,1,-2*day,day*day));
					break;
				}
			}

			num_recover = max_index+1;

		}
		recovery++;
	}

	for(int i = 0; i < N; i++){

		if(REC_DAY[i] == BIG_NUM){

			printf("Many years later\n");
		}else{

			printf("%lld\n",REC_DAY[i]);
		}
	}

	for(int i = 0; i < num_query; i++){

		printf("%lld\n",value[Y[i]]);
	}

	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 39408
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int LLNF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct Service{
	ll w;
	int t,x;
	bool operator<(const Service &s)const{
		return true;
	}
};

void Solve(){
	int n,q;
	cin >> n >> q;

	queue<Service> qs;
	vector<int> anss;
	rep(i,0,n){
		ll w;
		int t,x;
		cin >> w >> t >> x;
		qs.push(Service{w,t,x});
	}
	
	queue<int> qy;
	vector<ll> ansy;
	rep(i,0,q){
		int y;
		cin >> y;
		qy.push(y);
	}
	
	const int limit=3652425;
	int num[3]={},days=0;
	ll restore=0,accel[3]={};
	priority_queue<pair<int,Service>,vector<pair<int,Service>>,greater<pair<int,Service>>> expire;
	rep(i,0,limit+1){
		if(qy.size()&&i==qy.front()){
			ansy.push_back(restore);
			qy.pop();
		}
		
		while(qs.size()&&restore>=qs.front().w){
			anss.push_back(i);
			Service service=qs.front();
			qs.pop();
			++num[service.t];
			if(service.t==0) ++accel[service.t];
			expire.push(mp(i+service.x,service));
		}

		while(expire.size()&&expire.top().first==i){
			Service service=expire.top().second;
			expire.pop();
			--num[service.t];
			if(service.t==0) --accel[service.t];
			else if(service.t==1) accel[service.t]-=service.x;
			else if(service.t==2){
				accel[service.t]-=(ll)service.x*service.x;
				days-=service.x;
			}
		}
		
		accel[1]+=num[1];
		accel[2]+=2*days+num[2];
		days+=num[2];
		rep(j,0,3) restore+=accel[j];
		++restore;
	}
	
	rep(i,0,n){
		if(anss.size()>i) cout << anss[i] << endl;
		else cout << "Many years later" << endl;
	}
	rep(i,0,q) cout << ansy[i] << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 6888
final_rank: 5

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

const ll day_lim = 3652425;

int main(){
  ll n,q;
  scanf("%lld%lld",&n,&q);
  vector<ll> w(n),t(n),x(n);
  rep(i,n)scanf("%lld%lld%lld",&w[i],&t[i],&x[i]);
  vector<ll> y(q);
  rep(i,q)scanf("%lld",&y[i]);
  
  ll pn = 0, pq = 0;
  priority_queue< pll, vector<pll>, greater<pll> > end;
  vector<ll> ansn(n,day_lim+1), ansq(q,day_lim+1);
  ll day=0, sum = 0, a=0,b=0,c=1;

  while(day<=day_lim){
    if(pq<q && y[pq] == day){
      ansq[pq] = sum;
      pq++;
    }

    while(pn<n && w[pn]<=sum){
      ansn[pn] = day;
      if(t[pn] == 0){
	c++;
      }else if(t[pn] == 1){
	b++; c-=day;
      }else if(t[pn] == 2){
	a++; b-=2*day; c+=day*day;
      }
      end.push(pll(day+x[pn],pn));
      pn++;
    }

    while(end.size() && end.top().first==day){
      ll id = end.top().second; end.pop();
      if(t[id] == 0){
	c--;
      }else if(t[id] == 1){
	b--; c+=ansn[id];
      }else if(t[id] == 2){
	a--; b+=2*ansn[id]; c-=ansn[id]*ansn[id];
      }
    }

    day++;
    sum += a*day*day + b*day + c;
    if(pn == n && pq==q)break; 
  }

  rep(i,n){
    if(ansn[i]>day_lim)puts("Many years later");
    else printf("%lld\n",ansn[i]);
  }
  rep(i,q)printf("%lld\n",ansq[i]);
}
accuracy: 1
time_ms: 70
memory_kb: 7292
final_rank: 2

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652427];
ll sub_a[3652427];
ll sub_b[3652427];
ll sub_c[3652427];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,0,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());

    for(ll day=1;day <= 3652425 + 1;day++){

      ll recover_level = all_log[day-1];

      while(next_target < total_services 
	    && services[next_target].lower_bound <= recover_level){
	recover_log[services[next_target].service_idx] = day - 1;

	if(services[next_target].type == 0){
	  c++;
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_c[day+services[next_target].speed_up_duration]++;
	  }
	}
	else if(services[next_target].type == 1){
	  b++;
	  c -= (day - 1);
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_b[day+services[next_target].speed_up_duration]++;
	    sub_c[day+services[next_target].speed_up_duration] -= (day-1);
	  }
	}
	else if(services[next_target].type == 2){
	  a++;
	  b -= 2*(day-1);
	  c += (day-1)*(day-1);
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_a[day+services[next_target].speed_up_duration]++;
	    sub_b[day+services[next_target].speed_up_duration] -= 2*(day-1);
	    sub_c[day+services[next_target].speed_up_duration] += (day-1) * (day-1);
	  }
	}
	next_target++;
      }

      a -= sub_a[day];
      b -= sub_b[day];
      c -= sub_c[day];
      all_log[day] = recover_level + a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 1
time_ms: 90
memory_kb: 119088
final_rank: 7

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652427];
ll sub_a[3652427];
ll sub_b[3652427];
ll sub_c[3652427];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,0,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());

    for(ll day=1;day <= 3652425 + 1;day++){

      ll recover_level = all_log[day-1];

      while(next_target < total_services 
	    && services[next_target].lower_bound <= recover_level){
	recover_log[services[next_target].service_idx] = day - 1;

	if(services[next_target].type == 0){
	  c++;
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_c[day+services[next_target].speed_up_duration]++;
	  }
	}
	else if(services[next_target].type == 1){
	  b++;
	  c += -(day - 1);
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_b[day+services[next_target].speed_up_duration]++;
	    sub_c[day+services[next_target].speed_up_duration] += -(day-1);
	  }
	}
	else if(services[next_target].type == 2){
	  a++;
	  b += -2*(day-1);
	  c += (day-1)*(day-1);
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_a[day+services[next_target].speed_up_duration]++;
	    sub_b[day+services[next_target].speed_up_duration] += -2*(day-1);
	    sub_c[day+services[next_target].speed_up_duration] += (day-1) * (day-1);
	  }
	}
	next_target++;
      }

      a -= sub_a[day];
      b -= sub_b[day];
      c -= sub_c[day];
      all_log[day] = recover_level + a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 1
time_ms: 90
memory_kb: 119004
final_rank: 6

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652427];
ll sub_a[3652427];
ll sub_b[3652427];
ll sub_c[3652427];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,0,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());

    for(int day=1;day <= 3652425 + 1;day++){

      ll recover_level = all_log[day-1];

      while(next_target < total_services 
	    && services[next_target].lower_bound <= recover_level){
	recover_log[services[next_target].service_idx] = day - 1;

	if(services[next_target].type == 0){
	  c++;
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_c[day+services[next_target].speed_up_duration]++;
	  }
	}
	else if(services[next_target].type == 1){
	  b++;
	  c += -(day - 1);
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_b[day+services[next_target].speed_up_duration]++;
	    sub_c[day+services[next_target].speed_up_duration] += -(day-1);
	  }
	}
	else if(services[next_target].type == 2){
	  a++;
	  b += -2*(day-1);
	  c += (day-1)*(day-1);
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_a[day+services[next_target].speed_up_duration]++;
	    sub_b[day+services[next_target].speed_up_duration] += -2*(day-1);
	    sub_c[day+services[next_target].speed_up_duration] += (day-1) * (day-1);
	  }
	}
	next_target++;
      }

      a -= sub_a[day];
      b -= sub_b[day];
      c -= sub_c[day];
      all_log[day] = recover_level + a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118712
final_rank: 17

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652427];
ll sub_a[3652427];
ll sub_b[3652427];
ll sub_c[3652427];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,0,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());
    for(int day=1;day <= 3652425 + 1;day++){

      ll recover_level = all_log[day-1];

      while(next_target < total_services 
	    && services[next_target].lower_bound <= recover_level){
	recover_log[services[next_target].service_idx] = day - 1;

	if(services[next_target].type == 0){
	  c += 1;
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_c[day+services[next_target].speed_up_duration] -= 1;
	  }
	}
	else if(services[next_target].type == 1){
	  b += 1;
	  c -= day - 1;
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_b[day+services[next_target].speed_up_duration] -= 1;
	    sub_c[day+services[next_target].speed_up_duration] += day - 1;
	  }
	}
	else if(services[next_target].type == 2){
	  a += 1;
	  b -= 2*(day-1);
	  c += (day-1)*(day-1);
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_a[day+services[next_target].speed_up_duration] -= 1;
	    sub_b[day+services[next_target].speed_up_duration] += 2*(day-1);
	    sub_c[day+services[next_target].speed_up_duration] -= (day-1) * (day-1);
	  }
	}
	next_target++;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      all_log[day] = recover_level + a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118432
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652426];
ll sub_b[3652426];
ll sub_c[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,0,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());
    for(int day=1;day <= 3652425 + 1;day++){

      ll recover_level = all_log[day-1];

      while(next_target < total_services 
	    && services[next_target].lower_bound <= recover_level){
	recover_log[services[next_target].service_idx] = day - 1;

	if(services[next_target].type == 0){
	  c += 1;
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_c[day+services[next_target].speed_up_duration] -= 1;
	  }
	}
	else if(services[next_target].type == 1){
	  b += 1;
	  c -= day - 1;
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_b[day+services[next_target].speed_up_duration] -= 1;
	    sub_c[day+services[next_target].speed_up_duration] += day - 1;
	  }
	}
	else if(services[next_target].type == 2){
	  a += 1;
	  b -= 2*(day-1);
	  c += (day-1)*(day-1);
	  if(day + services[next_target].speed_up_duration <= 3652425 + 1) {
	    sub_a[day+services[next_target].speed_up_duration] -= 1;
	    sub_b[day+services[next_target].speed_up_duration] += 2*(day-1);
	    sub_c[day+services[next_target].speed_up_duration] -= (day-1) * (day-1);
	  }
	}
	next_target++;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      all_log[day] = recover_level + a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118968
final_rank: 18

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652426];
ll sub_b[3652426];
ll sub_c[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,0,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());
    for(int day=1;day <= 3652425 + 1;day++){

      ll recover_level = all_log[day-1];

      while(next_target < total_services 
	    && services[next_target].lower_bound <= recover_level){
	recover_log[services[next_target].service_idx] = day - 1;

	if(services[next_target].type == 0){
	  c += 1;
	  if(day + services[next_target].speed_up_duration <= 3652425) {
	    sub_c[day+services[next_target].speed_up_duration] -= 1;
	  }
	}
	else if(services[next_target].type == 1){
	  b += 1;
	  c -= day - 1;
	  if(day + services[next_target].speed_up_duration <= 3652425) {
	    sub_b[day+services[next_target].speed_up_duration] -= 1;
	    sub_c[day+services[next_target].speed_up_duration] += day - 1;
	  }
	}
	else if(services[next_target].type == 2){
	  a += 1;
	  b -= 2*(day-1);
	  c += (day-1)*(day-1);
	  if(day + services[next_target].speed_up_duration <= 3652425) {
	    sub_a[day+services[next_target].speed_up_duration] -= 1;
	    sub_b[day+services[next_target].speed_up_duration] += 2*(day-1);
	    sub_c[day+services[next_target].speed_up_duration] -= (day-1) * (day-1);
	  }
	}
	next_target++;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      all_log[day] = recover_level + a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118432
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652426];
ll sub_b[3652426];
ll sub_c[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,-1,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=0;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());
    for(int day=0;day <= 3652425;day++){
      recover_level += a * day * day + b * day + c;
      all_log[day] = recover_level;


      while(next_target < total_services 
	    && services[next_target].lower_bound <= recover_level){
	recover_log[services[next_target].service_idx] = day;

	if(services[next_target].type == 0){
	  c += 1;
	  if(day + services[next_target].speed_up_duration <= 3652425) {
	    sub_c[day+services[next_target].speed_up_duration] -= 1;
	  }
	}
	else if(services[next_target].type == 1){
	  b += 1;
	  c -= day;
	  if(day + services[next_target].speed_up_duration <= 3652425) {
	    sub_b[day+services[next_target].speed_up_duration] -= 1;
	    sub_c[day+services[next_target].speed_up_duration] += day;
	  }
	}
	else if(services[next_target].type == 2){
	  a += 1;
	  b -= 2*day;
	  c += day*day;
	  if(day + services[next_target].speed_up_duration <= 3652425) {
	    sub_a[day+services[next_target].speed_up_duration] -= 1;
	    sub_b[day+services[next_target].speed_up_duration] += 2*day;
	    sub_c[day+services[next_target].speed_up_duration] -= day * day;
	  }
	}
	next_target++;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      if(day == 0) c++; //default
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 119088
final_rank: 19

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652426];
ll sub_b[3652426];
ll sub_c[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,-1,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=0;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());
    for(int day=0;day <= 3652425;day++){
      recover_level += a * day * day + b * day + c;
      all_log[day] = recover_level;


      while(next_target < total_services 
	    && services[next_target].lower_bound <= recover_level){
	recover_log[services[next_target].service_idx] = day;

	if(services[next_target].type == 0){
	  c += 1;
	  if(day + day+services[next_target].speed_up_duration <= 3652425) {
	    sub_c[day+services[next_target].speed_up_duration] -= 1;
	  }
	}
	else if(services[next_target].type == 1){
	  b += 1;
	  c -= day;
	  if(day + day+services[next_target].speed_up_duration <= 3652425) {
	    sub_b[day+services[next_target].speed_up_duration] -= 1;
	    sub_c[day+services[next_target].speed_up_duration] += day;
	  }
	}
	else if(services[next_target].type == 2){
	  a += 1;
	  b -= 2*day;
	  c += day*day;
	  if(day + day+services[next_target].speed_up_duration <= 3652425) {
	    sub_a[day+services[next_target].speed_up_duration] -= 1;
	    sub_b[day+services[next_target].speed_up_duration] += 2*day;
	    sub_c[day+services[next_target].speed_up_duration] -= day * day;
	  }
	}
	next_target++;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      if(day == 0) c++; //default
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118432
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652426];
ll sub_b[3652426];
ll sub_c[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,-1,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=0;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());
    for(int day=0;day <= 3652425;day++){
      recover_level += a * day * day + b * day + c;
      all_log[day] = recover_level;

      for(int i = next_target;
	  (i < total_services)
	   && (services[i].lower_bound <= recover_level);
	   i++){
	recover_log[services[i].service_idx] = day;

	if(services[i].type == 0){
	  c += 1;
	  if(day + day+services[i].speed_up_duration <= 3652425) {
	    sub_c[day+services[i].speed_up_duration] -= 1;
	  }
	}
	else if(services[i].type == 1){
	  b += 1;
	  c -= day;
	  if(day + day+services[i].speed_up_duration <= 3652425) {
	    sub_b[day+services[i].speed_up_duration] -= 1;
	    sub_c[day+services[i].speed_up_duration] += day;
	  }
	}
	else if(services[i].type == 2){
	  a += 1;
	  b -= 2*day;
	  c += day*day;
	  if(day + day+services[i].speed_up_duration <= 3652425) {
	    sub_a[day+services[i].speed_up_duration] -= 1;
	    sub_b[day+services[i].speed_up_duration] += 2*day;
	    sub_c[day+services[i].speed_up_duration] -= day * day;
	  }
	}
	next_target = i+1;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      if(day == 0) c++; //default
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118456
final_rank: 15

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652426];
ll sub_b[3652426];
ll sub_c[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,-1,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=0;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());
    for(int day=0;day <= 3652425;day++){
      recover_level += a * day * day + b * day + c;
      all_log[day] = recover_level;

      for(int i = next_target; i < total_services; i++){
	if(services[i].lower_bound > recover_level) break;

	recover_log[services[i].service_idx] = day;

	if(services[i].type == 0){
	  c += 1;
	  if(day + day+services[i].speed_up_duration <= 3652425) {
	    sub_c[day+services[i].speed_up_duration] -= 1;
	  }
	}
	else if(services[i].type == 1){
	  b += 1;
	  c -= day;
	  if(day + day+services[i].speed_up_duration <= 3652425) {
	    sub_b[day+services[i].speed_up_duration] -= 1;
	    sub_c[day+services[i].speed_up_duration] += day;
	  }
	}
	else if(services[i].type == 2){
	  a += 1;
	  b -= 2*day;
	  c += day*day;
	  if(day + day+services[i].speed_up_duration <= 3652425) {
	    sub_a[day+services[i].speed_up_duration] -= 1;
	    sub_b[day+services[i].speed_up_duration] += 2*day;
	    sub_c[day+services[i].speed_up_duration] -= day * day;
	  }
	}
	next_target = i+1;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      if(day == 0) c++; //default
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118432
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652426];
ll sub_b[3652426];
ll sub_c[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,-1,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=0;//f = ax^2 + b^x+c

    sort(services.begin(),services.end());
    for(int day=0;day <= 3652425;day++){
      recover_level += a * day * day + b * day + c;
      all_log[day] = recover_level;

      for(int i = next_target; i < total_services; i++){
	if(services[i].lower_bound > recover_level) break;

	recover_log[services[i].service_idx] = day;

	if(services[i].type == 0){
	  c += 1;
	  sub_c[day+services[i].speed_up_duration] -= 1;
	}
	else if(services[i].type == 1){
	  b += 1;
	  c -= day;
	  sub_b[day+services[i].speed_up_duration] -= 1;
	  sub_c[day+services[i].speed_up_duration] += day;
	}
	else if(services[i].type == 2){
	  a += 1;
	  b -= 2*day;
	  c += day*day;
	  sub_a[day+services[i].speed_up_duration] -= 1;
	  sub_b[day+services[i].speed_up_duration] += 2*day;
	  sub_c[day+services[i].speed_up_duration] -= day * day;
	}
	next_target = i+1;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      if(day == 0) c++;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118444
final_rank: 14

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652426];
ll sub_b[3652426];
ll sub_c[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    sort(services.begin(),services.end());
    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,-1,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    for(int day=0;day <= 3652425;day++){
      all_log[day] = recover_level;

      for(int i = next_target; i < total_services; i++){
	if(services[i].lower_bound > recover_level) break;
	recover_log[services[i].service_idx] = day;
	if(services[i].type == 0){
	  c += 1;
	  sub_c[day+services[i].speed_up_duration] -= 1;
	}
	else if(services[i].type == 1){
	  b += 1;
	  c -= day-1;
	  sub_b[day+services[i].speed_up_duration] -= 1;
	  sub_c[day+services[i].speed_up_duration] += day-1;
	}
	else if(services[i].type == 2){
	  a += 1;
	  b -= 2*(day-1);
	  c += (day-1)*(day-1);
	  sub_a[day+services[i].speed_up_duration] -= 1;
	  sub_b[day+services[i].speed_up_duration] += 2*(day-1);
	  sub_c[day+services[i].speed_up_duration] -= (day-1) * (day-1);
	}
	next_target = i+1;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      recover_level += a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118476
final_rank: 16

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652425];
ll sub_b[3652425];
ll sub_c[3652425];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si){}
  bool operator<(const Service& s) const{
    return lower_bound < s.lower_bound;
  }
  bool operator>(const Service& s) const{
    return lower_bound > s.lower_bound;
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    sort(services.begin(),services.end());
    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,-1,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    for(int day=0;day <= 3652425;day++){
      all_log[day] = recover_level;

      for(int i = next_target; i < total_services; i++){
	if(services[i].lower_bound > recover_level) break;
	recover_log[services[i].service_idx] = day;
	if(services[i].type == 0){
	  c += 1;
	  sub_c[day+services[i].speed_up_duration] -= 1;
	}
	else if(services[i].type == 1){
	  b += 1;
	  c -= day-1;
	  sub_b[day+services[i].speed_up_duration] -= 1;
	  sub_c[day+services[i].speed_up_duration] += day-1;
	}
	else if(services[i].type == 2){
	  a += 1;
	  b -= 2*(day-1);
	  c += (day-1)*(day-1);
	  sub_a[day+services[i].speed_up_duration] -= 1;
	  sub_b[day+services[i].speed_up_duration] += 2*(day-1);
	  sub_c[day+services[i].speed_up_duration] -= (day-1) * (day-1);
	}
	next_target = i+1;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      recover_level += a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118432
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll all_log[3652426];
ll sub_a[3652425];
ll sub_b[3652425];
ll sub_c[3652425];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  int day;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si),day(0){}

  Service(const Service& s,int _d){
    lower_bound = s.lower_bound;
    type = s.type;
    speed_up_duration = s.speed_up_duration;
    service_idx = s.service_idx;
    day = _d;
  }

  bool operator<(const Service& s) const{
    return day < s.day;
  }
  bool operator>(const Service& s) const{
    return day > s.day;
  }

  ll compute_recover(ll passed_days) const{
    if(type == 0){
      return 1;
    }
    else if(type == 1){
      return passed_days;
    }
    else if(type == 2){
      return passed_days * passed_days;
    }
  }
  ll compute_recover(ll first,ll last) const{
    last = min((ll)speed_up_duration,last);
    first = min((ll)speed_up_duration+1,first);

    ll minus = 0; 
    if(first > 0){
      if(type == 0){
	minus = first - 1;
      }
      else if(type == 1){
	minus = (first-1) * (1 + (first-1)) / 2;
      }
      else if(type == 2){
	minus = (first-1)*(first)*(2*(first-1)+1) / 6;
      }
    }

    if(type == 0){
      return last - minus;
    }
    else if(type == 1){
      return last * (1 + last) / 2 - minus;
    }
    else if(type == 2){
      return last*(last+1)*(2*last+1) / 6 - minus;
    }
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(all_log,-1,sizeof(all_log));

    memset(sub_a,0,sizeof(sub_a));
    memset(sub_b,0,sizeof(sub_b));
    memset(sub_c,0,sizeof(sub_c));

    int next_target = 0;
    ll a=0,b=0,c=1;//f = ax^2 + b^x+c

    for(int day=0;day <= 3652425;day++){
      all_log[day] = recover_level;

      for(int i = next_target; i < total_services; i++){
	if(services[i].lower_bound > recover_level) break;
	recover_log[i] = day;
	if(services[i].type == 0){
	  c += 1;
	  sub_c[day+services[i].speed_up_duration] -= 1;
	}
	else if(services[i].type == 1){
	  b += 1;
	  c -= day-1;
	  sub_b[day+services[i].speed_up_duration] -= 1;
	  sub_c[day+services[i].speed_up_duration] += day-1;
	}
	else if(services[i].type == 2){
	  a += 1;
	  b -= 2*(day-1);
	  c += (day-1)*(day-1);
	  sub_a[day+services[i].speed_up_duration] -= 1;
	  sub_b[day+services[i].speed_up_duration] += 2*(day-1);
	  sub_c[day+services[i].speed_up_duration] -= (day-1) * (day-1);
	}
	next_target = i+1;
      }

      a += sub_a[day];
      b += sub_b[day];
      c += sub_c[day];
      recover_level += a * day * day + b * day + c;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",all_log[day]);
    }
  }
}
accuracy: 0.43333333333333335
time_ms: 60
memory_kb: 118432
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const ll MAX = 1e15;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll recover_log[100001];
ll level_log[3652426];

class Service{
public:
  ll lower_bound;
  int type;
  int speed_up_duration;
  int service_idx;
  int day;
  Service(ll _l,int _t,int _s,int _si)
    : lower_bound(_l),type(_t),speed_up_duration(_s),service_idx(_si),day(0){}

  Service(const Service& s,int _d){
    lower_bound = s.lower_bound;
    type = s.type;
    speed_up_duration = s.speed_up_duration;
    service_idx = s.service_idx;
    day = _d;
  }

  bool operator<(const Service& s) const{
    return day + speed_up_duration < s.day + s.speed_up_duration;
  }
  bool operator>(const Service& s) const{
    return day + speed_up_duration > s.day + s.speed_up_duration;
  }

  ll compute_recover(ll passed_days) const{
    if(type == 0){
      return 1;
    }
    else if(type == 1){
      return passed_days;
    }
    else if(type == 2){
      return passed_days * passed_days;
    }
  }
  ll compute_recover(ll first,ll last) const{
    last = min((ll)speed_up_duration,last);
    first = min((ll)speed_up_duration+1,first);

    ll minus = 0; 
    if(first > 0){
      if(type == 0){
	minus = first - 1;
      }
      else if(type == 1){
	minus = (first-1) * (1 + (first-1)) / 2;
      }
      else if(type == 2){
	minus = (first-1)*(first)*(2*(first-1)+1) / 6;
      }
    }

    if(type == 0){
      return last - minus;
    }
    else if(type == 1){
      return last * (1 + last) / 2 - minus;
    }
    else if(type == 2){
      return last*(last+1)*(2*last+1) / 6 - minus;
    }
  }
};

int main(){
  int total_services;
  int seek_duration;

  while(~scanf("%d %d",&total_services,&seek_duration)){

    vector<Service> services;
    for(int service_idx = 0; service_idx < total_services; service_idx++){
      ll lower_bound;
      int type;
      int speed_up_duration;
      scanf("%lld %d %d",&lower_bound,&type,&speed_up_duration);
      services.push_back(Service(lower_bound,type,speed_up_duration,service_idx));
    }

    ll recover_level = 0;
    memset(recover_log,-1,sizeof(recover_log));   
    memset(level_log,-1,sizeof(level_log));

    set<Service,greater<Service> > provider;
    
    int next_target = 0;
    for(int day=0;day <= 3652425;day++){
      ll add_recover_level = 0;

      for(set<Service>::iterator it = provider.begin();
	  it != provider.end();
	  it++){
	ll passed_days = day - it->day;
	if(passed_days > it->speed_up_duration) break;
	add_recover_level += it->compute_recover(passed_days);
      }

      for(int i = next_target; i < total_services; i++){
	if(services[i].lower_bound > recover_level + add_recover_level) break;
	if(recover_log[i] != -1) break;
	recover_log[i] = day;
	provider.insert(Service(services[i],day));
	next_target = i+1;
      }

      level_log[day] = recover_level + add_recover_level;      
      recover_level += add_recover_level + 1;
    }

    for(int service_idx = 0; service_idx < total_services;service_idx++){
      if(recover_log[service_idx] == -1){
	printf("Many years later\n");
      }
      else {
	printf("%lld\n",recover_log[service_idx]);
      }
    }

    for(int seek_idx = 0; seek_idx < seek_duration; seek_idx++){
      int day;
      scanf("%d",&day);
      printf("%lld\n",level_log[day]);
    }
  }
}
accuracy: 0.03333333333333333
time_ms: 40
memory_kb: 30600
final_rank: 20