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;
}
相关推荐
星恒随风8 分钟前
C++ 继承进阶:默认成员函数、多继承、虚继承与组合设计
开发语言·c++·笔记·学习
呜喵王阿尔萨斯1 小时前
C/C++ const -- 多义混乱
c语言·开发语言·c++
海清河晏1111 小时前
Qt实战:从零构建美化登录界面
开发语言·c++·qt
一只小灿灿1 小时前
C++ 各类特殊符号、运算符
开发语言·c++
晚风叙码1 小时前
C++ vector底层模拟实现与迭代器失效深度剖析
c++·算法
2401_8414956410 小时前
【操作系统】进程同步与互斥实验报告
c++·算法·操作系统·进程·并发·同步·互斥
fqbqrr10 小时前
2607C++,soui与安卓
c++·soui
fqbqrr14 小时前
2607C++,使用微软detours勾挂工具
c++
蓝悦无人机17 小时前
C++基础 — 函数总结
开发语言·c++
我不是懒洋洋18 小时前
从零实现一个分布式监控:Prometheus的核心设计
c++