当前位置:网站首页>Niuke cold training camp 6B (Freund has no green name level)

Niuke cold training camp 6B (Freund has no green name level)

2022-07-07 01:02:00 Find a derivative first

subject
The question : Given length is n Array of a, Find out how many subsequences have the same value as the whole array .( Are positive integers )
value : Sigma 1 To n-1 |a[i] - a[i+1]|. The length is 1 The value of the subsequence of is specified as 0.
Ideas : The example gives many hints . For an interval of the same number , It doesn't matter to delete . But be careful , Can you delete it all ?
Suppose he is not a peak or trough , Cannot delete all .Cn0 + Cn1 + … Cnn - 1 = 2^n - 1.
Otherwise, it doesn't hurt to delete it all .
 Insert picture description here
If it is a crest or trough , And b irrelevant .
Time complexity : O(n)
Code :

// Problem:  Value sequence 
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/23481/B
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<complex>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<list>
#include<set>
#include<queue>
#include<stack>
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i<=b;++i) 
#define mem(a,x) memset(a,x,sizeof(a))
#define p_ priority_queue
// round()  rounding  ceil()  Rounding up  floor()  Rounding down 
// lower_bound(a.begin(),a.end(),tmp,greater<ll>())  First less than or equal to 
// #define int long long //QAQ
using namespace std;
typedef complex<double> CP;
typedef pair<int,int> PII;
typedef long long ll;
// typedef __int128 it;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const int N = 2e5+10;
const int M = 1e6+10;
const int mod = 998244353;
const double eps = 1e-6;
inline int lowbit(int x){
     return x&(-x);}
template<typename T>void write(T x)
{
    
    if(x<0)
    {
    
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
    
        write(x/10);
    }
    putchar(x%10+'0');
}
template<typename T> void read(T &x)
{
    
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){
    if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){
    x = x*10+ch-48;ch=getchar();}x*=f;
}
int n,m,k,T;
ll qpow(int a,int k)
{
    
	ll res = 1;
	while(k)
	{
    
		if(k&1) res = res * a % mod;
		a = a * a % mod;
		k >>= 1;
	}
	return res;
}
void solve()
{
    
   read(n);
   vector<int> a(n+2);
   vector<PII> va;
   for(int i=1;i<=n;++i)
   {
    
   	  read(a[i]);
   }
   for(int i=1;i<=n;)
   {
    
   	  int j = i;
   	  while(j+1<=n&&a[i]==a[j+1]) j++;
   	  va.push_back({
    a[i],j-i+1});
   	  i = j+1;
   }
   int ans = 1;
   for(int i=0;i<va.size();++i)
   {
    
   	   // cout<<i<<":"<<va[i].second<<endl;
   	   if(i==0||i==va.size()-1||(va[i]>va[i-1])==(va[i]>va[i+1]))
   	   {
    
   	   	 ans = ( ans * (qpow(2,va[i].second)-1) ) % mod;
   	   }
   	   else 
   	   {
    
   	   	 ans = ( ans * qpow(2,va[i].second) ) % mod;
   	   }
   }
   ans = (ans + mod) % mod;
   write(ans); puts("");
}
signed main(void)
{
      
   // T = 1;
   // OldTomato; cin>>T;
   read(T);
   while(T--)
   {
    
   	 solve();
   }
   return 0;
}

原网站

版权声明
本文为[Find a derivative first]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130938471449.html