Master of Sequence

题目描述

There are two sequences a1,a2,...,an , b1,b2,...,bn . Let . There are m operations within three kinds as following:
• 1 x y: change value ax to y.
• 2 x y: change value bx to y.
• 3 k: ask min{t|k≤S(t)}

 

输入

The first line contains a integer T (1≤T≤5) representing the number of test cases.
For each test case, the first line contains two integers n (1≤n≤100000), m (1≤m≤10000).
The following line contains n integers representing the sequence a1,a2,...,an .
The following line contains n integers representing the sequence b1,b2,...,bn .
The following m lines, each line contains two or three integers representing an operation mentioned above.
It is guaranteed that, at any time, we have 1≤ai≤1000, 1≤bi,k≤109 . And the number of queries (type 3 operation) in each test case will not exceed 1000.

 

输出

For each query operation (type 3 operation), print the answer in one line.

 

样例输入

复制样例数据

2
4 6
2 4 6 8
1 3 5 7
1 2 3
2 3 3
3 15
1 3 8
3 90
3 66
8 5
2 4 8 3 1 3 6 24
2 2 39 28 85 25 98 35
3 67
3 28
3 73
3 724
3 7775

样例输出

17
87
65
72
58
74
310
2875
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
const ll mod=998244353;
const int maxn=1e6+50;
#define lowbit(x)  x&(-x)
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
ll qmod(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
ll inv(ll a)
{
    return qmod(a,mod-2);
}
int a[maxn],b[maxn],num[1050][1050],n;
int t;
bool check(ll x,ll s)
{
    ll ret=0;
    for(int i=1;i<=1000;i++)
    {
        ret+=x/i*num[i][0];
        ret-=num[i][x%i+1];
    }
    if(s<=ret)
    {
        return true;
    }
    return false;
}
ll fun(ll x)
{
    ll l=1,r=1e13,mid;
    while(l<r)
    {
        mid=(l+r)>>1;
        if(check(mid,x))
        {
            r=mid;
        }
        else
        {
            l=mid+1;
        }
    }
    return l;
}
int main()
{
    scanf("%d",&t);
    int n,x,y,z,T;
    ll ret;
    while(t--)
    {
        scanf("%d %d",&n,&T);
        ret=0;
        for(int i=1;i<=1000;i++)
        {
            for(int j=0;j<i;j++)
            {
                num[i][j]=0;
            }
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&b[i]);
            ret+=(b[i]/a[i]);
            num[a[i]][b[i]%a[i]]++;
        }
        for(int i=1;i<=1000;i++)
        {
            for(int j=i-1;j>=0;j--)
            {
                num[i][j]+=num[i][j+1];
            }
        }
        while(T--)
        {
            scanf("%d %d",&z,&x);
            if(z==1)
            {
                scanf("%d",&y);
                for(int i=b[x]%a[x];i>=0;i--)
                {
                    num[a[x]][i]--;
                }
                for(int i=b[x]%y;i>=0;i--)
                {
                    num[y][i]++;
                }
                ret-=(b[x]/a[x]);
                ret+=(b[x]/y);
                a[x]=y;
            }
            else if(z==2)
            {
                scanf("%d",&y);
                for(int i=b[x]%a[x];i>=0;i--)
                {
                    num[a[x]][i]--;
                }
                for(int i=y%a[x];i>=0;i--)
                {
                    num[a[x]][i]++;
                }
                ret-=(b[x]/a[x]);
                ret+=(y/a[x]);
                b[x]=y;
            }
            else
            {
                printf("%lld\n",fun(ret+x));
            }
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Traceback (most recent call last): File "pandas\_libs\tslibs\timedeltas.pyx", line 354, in pandas._libs.tslibs.timedeltas.array_to_timedelta64 File "pandas\_libs\tslibs\timedeltas.pyx", line 409, in pandas._libs.tslibs.timedeltas.parse_timedelta_string ValueError: only leading negative signs are allowed During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\desktop\st_dbscan-master\demo\ais.py", line 32, in <module> df['BaseDateTime'] = pd.to_timedelta(df['BaseDateTime']) File "C:\ProgramData\Anaconda3\envs\tf2.6\lib\site-packages\pandas\core\tools\timedeltas.py", line 124, in to_timedelta values = _convert_listlike(arg._values, unit=unit, errors=errors) File "C:\ProgramData\Anaconda3\envs\tf2.6\lib\site-packages\pandas\core\tools\timedeltas.py", line 173, in _convert_listlike td64arr = sequence_to_td64ns(arg, unit=unit, errors=errors, copy=False)[0] File "C:\ProgramData\Anaconda3\envs\tf2.6\lib\site-packages\pandas\core\arrays\timedeltas.py", line 991, in sequence_to_td64ns data = objects_to_td64ns(data, unit=unit, errors=errors) File "C:\ProgramData\Anaconda3\envs\tf2.6\lib\site-packages\pandas\core\arrays\timedeltas.py", line 1100, in objects_to_td64ns result = array_to_timedelta64(values, unit=unit, errors=errors) File "pandas\_libs\tslibs\timedeltas.pyx", line 368, in pandas._libs.tslibs.timedeltas.array_to_timedelta64 File "pandas\_libs\tslibs\timedeltas.pyx", line 359, in pandas._libs.tslibs.timedeltas.array_to_timedelta64 File "pandas\_libs\tslibs\timedeltas.pyx", line 300, in pandas._libs.tslibs.timedeltas.convert_to_timedelta64 File "pandas\_libs\tslibs\timedeltas.pyx", line 409, in pandas._libs.tslibs.timedeltas.parse_timedelta_string ValueError: only leading negative signs are allowed 进程已结束,退出代码1
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值