当前位置:网站首页>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;
}
边栏推荐
- Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
- 深度学习简史(一)
- Service asynchronous communication
- from .cv2 import * ImportError: libGL.so.1: cannot open shared object file: No such file or direc
- Zabbix 5.0:通过LLD方式自动化监控阿里云RDS
- 接口(接口相关含义,区别抽象类,接口回调)
- 深入探索编译插桩技术(四、ASM 探秘)
- [software reverse automation] complete collection of reverse tools
- 【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
- 【软件逆向-自动化】逆向工具大全
猜你喜欢
Slam d'attention: un slam visuel monoculaire appris de l'attention humaine
Service asynchronous communication
Deep understanding of distributed cache design
城联优品入股浩柏国际进军国际资本市场,已完成第一步
重上吹麻滩——段芝堂创始人翟立冬游记
Make a simple graphical interface with Tkinter
[Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
第五篇,STM32系统定时器和通用定时器编程
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
[100 cases of JVM tuning practice] 04 - Method area tuning practice (Part 1)
随机推荐
通过串口实现printf函数,中断实现串口数据接收
浅谈测试开发怎么入门,如何提升?
Rainstorm effect in levels - ue5
「精致店主理人」青年创业孵化营·首期顺德场圆满结束!
A brief history of deep learning (II)
深度学习之线性代数
Three methods to realize JS asynchronous loading
Stm32f407 ------- DAC digital to analog conversion
A brief history of deep learning (I)
UI控件Telerik UI for WinForms新主题——VS2022启发式主题
Part VI, STM32 pulse width modulation (PWM) programming
深度学习简史(一)
Learning notes 5: ram and ROM
Fastdfs data migration operation record
Advantages and disadvantages of code cloning
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
Deep learning framework TF installation
Dell笔记本周期性闪屏故障
Slam d'attention: un slam visuel monoculaire appris de l'attention humaine
equals()与hashCode()