当前位置:网站首页>B. Value sequence thinking

B. Value sequence thinking

2022-07-07 08:01:00 Wawa source

Value sequence — thinking

Numerical peaks and valleys cannot be moved , Optional in other positions
We regard the same number as a whole

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int>PII;
#define int long long
const int N =100010,mod=998244353;
int n;
int a[N];
int qmi(int a,int b)
{
    
    int res=1;
    while(b)
    {
    
        if(b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}
void solve()
{
    
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    int res=1;
    for(int i=0;i<n;i++)
    {
    
        int j=i;
        while(j+1<n&&a[j+1]==a[i])j++;
        if(i-1>=0&&j+1<n&&((a[i]>a[i-1]&&a[i]<a[j+1])||(a[i]<a[i-1]&&a[i]>a[j+1])))
        {
    
            res=res*qmi(2,j-i+1)%mod;
        }
        else res=res*(qmi(2,j-i+1)-1)%mod;
        i=j;
    }
    cout<<res<<'\n';
}
signed main()
{
    
    int T;
    cin>>T;
    while(T--)solve();
}
原网站

版权声明
本文为[Wawa source]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130647365734.html