1498D. Bananas in a Microwave

D. Bananas in a Microwave time limit per test3 seconds memory limit
per test256 megabytes inputstandard input outputstandard output You
have a malfunctioning microwave in which you want to put some bananas.
You have n time-steps before the microwave stops working completely.
At each time-step, it displays a new operation.

Let k be the number of bananas in the microwave currently. Initially,
k=0. In the i-th operation, you are given three parameters ti, xi, yi
in the input. Based on the value of ti, you must do one of the
following:

Type 1: (ti=1, xi, yi) — pick an ai, such that 0≤ai≤yi, and perform
the following update ai times: k:=⌈(k+xi)⌉.

Type 2: (ti=2, xi, yi) — pick an ai, such that 0≤ai≤yi, and perform
the following update ai times: k:=⌈(k⋅xi)⌉.

Note that xi can be a fractional value. See input format for more
details. Also, ⌈x⌉ is the smallest integer ≥x.

At the i-th time-step, you must apply the i-th operation exactly once.

For each j such that 1≤j≤m, output the earliest time-step at which you
can create exactly j bananas. If you cannot create exactly j bananas,
output −1.

Input The first line contains two space-separated integers n (1≤n≤200)
and m (2≤m≤105).

Then, n lines follow, where the i-th line denotes the operation for
the i-th timestep. Each such line contains three space-separated
integers ti, x′i and yi (1≤ti≤2, 1≤yi≤m).

Note that you are given x′i, which is 105⋅xi. Thus, to obtain xi, use
the formula xi=x′i105.

For type 1 operations, 1≤x′i≤105⋅m, and for type 2 operations,
105<x′i≤105⋅m.

Output Print m integers, where the i-th integer is the earliest
time-step when you can obtain exactly i bananas (or −1 if it is
impossible).

Examples inputCopy 3 20 1 300000 2 2 400000 2 1 1000000 3 outputCopy
-1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 inputCopy 3 20 1 399999 2 2 412345 2 1 1000001 3 outputCopy
-1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in
three timesteps. Initially, k=0.

In timestep 1, we choose a1=2, so we apply the type 1 update —
k:=⌈(k+3)⌉ — two times. Hence, k is now 6. In timestep 2, we choose
a2=0, hence value of k remains unchanged. In timestep 3, we choose
a3=1, so we are applying the type 1 update k:=⌈(k+10)⌉ once. Hence, k
is now 16. It can be shown that k=16 cannot be reached in fewer than
three timesteps with the given operations.

In the second sample input, let us see how to create 17 number of
bananas in two timesteps. Initially, k=0.

In timestep 1, we choose a1=1, so we apply the type 1 update —
k:=⌈(k+3.99999)⌉ — once. Hence, k is now 4. In timestep 2, we choose
a2=1, so we apply the type 2 update — k:=⌈(k⋅4.12345)⌉ — once. Hence,
k is now 17. It can be shown that k=17 cannot be reached in fewer than
two timesteps with the given operations.

应当注意向上取整的写法

//cyc
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define vector<int> VI
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mst(a) memset(a,-1,sizeof a)
#define int long long
using namespace std;
typedef pair<int,int> pii;
const int maxn=1e5+5;
const int divi=1e5;

int ans[maxn];
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n,n0,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)ans[i]=-1;
    n0=n;
    int t,x,y;
    int k=0;
    ans[0]=0;
    int cur=0;
    int cnt=0;
    while(n--){
        cin>>t>>x>>y;

        for(int i=m;i>=0;i--){

            if(ans[i]==-1)continue;
            cur=i;
            for(int j=1;j<=y;j++){
                if(t==1)cur=cur+(x+divi-1)/divi;
                else cur=(cur*x+divi-1)/divi;
                if(cur>m)break;
                if(ans[cur]!=-1){
                    break;//因为是倒着计算,如果出现重复,说明后面的数已经被计算过,就没必要继续计算下去了
                }
                ans[cur]=n0-n;
            }
        }

    }
    for(int i=1;i<=m;i++)cout<<ans[i]<<" ";
    cout<<endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值