edu158-B

好久没有做edu的b做到流汗了,很吊的一个思维(递推)题

给定一个now代表来到位置i,左边可用的芯片数,如果now>ai那么说明不会产生新的贡献,只需要更新一下now即可,否则我需要加上一个差值并更新now

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
const int N=1e6+10;
const int mod=998244353;
vector<int>pm;
int judge[N],nm[N],inv[N];
int Log2[N];
int kmi(int a,int b){
    int res=1;
    while(b){
        if(b&1) res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
void init(){
    nm[0]=inv[0]=1;
    for(int i=1;i<=1e6;i++){
        nm[i]=nm[i-1]*i%mod;
        inv[i]=kmi(nm[i],mod-2);
    }
}
void euler(int n){
    judge[1]=1;
    for(int i=2;i<=n;i++){
        if(!judge[i]){
            pm.push_back(i);
        }
        for(int j=0;pm[j]*i<=n;j++){
            judge[pm[j]*i]=1;
            if(i%pm[j]==0) break;
        }
    }
}
int C(int a,int b){
    return nm[a]*inv[a-b]%mod*inv[b]%mod;
}

void solve(){
    int n;cin>>n;
    int now=1;
    int ans=0;
    for(int i=1;i<=n;i++){
        int x;cin>>x;
        if(x<=now){
            now=x;
        }
        else{
            ans+=x-now;
            now=x;
        }
    }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    // for(int i=2;i<=1e6;i++){
    //     Log2[i]=Log2[i/2]+1;
    // }
    int T=1;cin>>T;
    while(T--) solve();
    return 0;
}
相关推荐
_Twink1e3 小时前
openJiuwen 实训营 Day 1 · WorkSwarm 入门教程
开发语言·c++·openjiuwen
dong_junshuai4 小时前
每天一个开源项目#87 fmt:24.5K Stars 的 C++ 格式化核心
c++·开源·github
雪的季节5 小时前
Multisim14.0的详细中文安装步骤【附安装包】
c++
Persistent的粽子!6 小时前
C++:类与对象(二)
开发语言·c++
蒸蒸yyyyzwd6 小时前
cpp 选手备战秋招学习笔记 day23
c++·求职招聘
.YM.Z7 小时前
C++ STL 容器深度剖析:vector 与 list 的模拟实现及对比
开发语言·c++·vector·list
mengzhi啊8 小时前
QEventLoop loop配合loop.exec();替代while(1)。电脑cpu占用为0,使用while(1)cpu占用率100%
c++·qt
HugoStudio_SWAN8 小时前
洛谷 P1319 / P1320 压缩技术——同一枚硬币的正反面
c++·学习·程序人生·算法
小小晓.9 小时前
C++单例模式万字详解:6种实现演进+线程安全彻底解决+CRTP终极模板
c++·单例模式
j7~10 小时前
【C++11】C++11 新特性全套详解(列表初始化、右值引用、lambda 表达式、function 与 bind 包装器等)
c++·右值引用·lambda表达式·可变参数模板·移动语义·包装器·c++11发展史