CF 1420/C2 Pokémon Army (hard version)
CF 1420/C2 Pokémon Army (hard version)
老下饭了 从性质想了很久 没想到怎么计算影响
本来想用线段树来维护每个段,大可不必
// by gwt using c++11
#include
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair pii;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define count2(x) __builtin_popcount(x)
#define countleadingzero(x) __builtin_clz(x)
#define debug(x) cerr << #x << " = " << x << endl;
inline ll read(){//not solve LLONG_MIN LMAX=9,223,372,036,854,775,807
ll s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0' && ch<='9')s=s*10+ch-'0',ch=getchar();
return s*w;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=read();
for(int _=1;_<=T;_++){
int n=read();
int q=read();
vectornums(n+1);
for(int j=1;j<=n;++j)
nums[j]=read();
ll ans=0;
ll sum=0;
vectorinclist;
vectorposlist;
for(int i=1;i<=n;++i){
if(inclist.empty()){
inclist.pb(nums[i]);
// poslist.pb(i);
}
else if(nums[i]needsolve={l-1,l,l+1,r-1,r,r+1};
for(auto t:needsolve){
if(t>0&&t<=n){
int valL=t-1>0?nums[t-1]:-1;
int valR=t+1<=n?nums[t+1]:-1;
if(nums[t]>valL&&nums[t]>valR)deta-=nums[t];
if(nums[t]0&&t<=n){
int valL=t-1>0?nums[t-1]:-1;
int valR=t+1<=n?nums[t+1]:-1;
if(nums[t]>valL&&nums[t]>valR)deta+=nums[t];
if(nums[t]