当前位置:网站首页>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 .
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;
}
边栏推荐
- Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
- Explain in detail the matrix normalization function normalize() of OpenCV [norm or value range of the scoped matrix (normalization)], and attach norm_ Example code in the case of minmax
- [牛客] B-完全平方数
- Zabbix 5.0:通过LLD方式自动化监控阿里云RDS
- 学习使用代码生成美观的接口文档!!!
- Dell筆記本周期性閃屏故障
- Data processing of deep learning
- [batch dos-cmd command - summary and summary] - view or modify file attributes (attrib), view and modify file association types (Assoc, ftype)
- mongodb客户端操作(MongoRepository)
- stm32F407-------SPI通信
猜你喜欢
Learn self 3D representation like ray tracing ego3rt
【JVM调优实战100例】05——方法区调优实战(下)
.class文件的字节码结构
C9 colleges and universities, doctoral students make a statement of nature!
Part VI, STM32 pulse width modulation (PWM) programming
. Bytecode structure of class file
「精致店主理人」青年创业孵化营·首期顺德场圆满结束!
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
【软件逆向-自动化】逆向工具大全
Attention SLAM:一種從人類注意中學習的視覺單目SLAM
随机推荐
threejs图片变形放大全屏动画js特效
A brief history of deep learning (II)
Learning notes 5: ram and ROM
Article management system based on SSM framework
Part 7: STM32 serial communication programming
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
Five different code similarity detection and the development trend of code similarity detection
Stm32f407 ------- SPI communication
.class文件的字节码结构
Attention slam: a visual monocular slam that learns from human attention
Advantages and disadvantages of code cloning
Cause of handler memory leak
【JokerのZYNQ7020】AXI_EMC。
深度学习之环境配置 jupyter notebook
什么是时间
代码克隆的优缺点
动态规划思想《从入门到放弃》
Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international
Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版