当前位置:网站首页>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;
}
边栏推荐
- Leetcode(547)——省份数量
- Meet the level 3 requirements of ISO 2.0 with the level B construction standard of computer room | hybrid cloud infrastructure
- Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international
- Summary of being a microservice R & D Engineer in the past year
- 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
- Attention SLAM:一种从人类注意中学习的视觉单目SLAM
- 第五篇,STM32系统定时器和通用定时器编程
- Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
- fastDFS数据迁移操作记录
- 【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
猜你喜欢
Summary of being a microservice R & D Engineer in the past year

BFS realizes breadth first traversal of adjacency matrix (with examples)

Part V: STM32 system timer and general timer programming
![【批处理DOS-CMD命令-汇总和小结】-跳转、循环、条件命令(goto、errorlevel、if、for[读取、切分、提取字符串]、)cmd命令错误汇总,cmd错误](/img/a5/41d4cbc070d421093323dc189a05cf.png)
【批处理DOS-CMD命令-汇总和小结】-跳转、循环、条件命令(goto、errorlevel、if、for[读取、切分、提取字符串]、)cmd命令错误汇总,cmd错误

详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码

ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版

Distributed cache

Slam d'attention: un slam visuel monoculaire appris de l'attention humaine

ZYNQ移植uCOSIII

界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
随机推荐
Advanced learning of MySQL -- basics -- multi table query -- inner join
Threejs image deformation enlarge full screen animation JS special effect
Attention SLAM:一种从人类注意中学习的视觉单目SLAM
用tkinter做一个简单图形界面
Deeply explore the compilation and pile insertion technology (IV. ASM exploration)
【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
stm32F407-------SPI通信
Advanced learning of MySQL -- basics -- multi table query -- subquery
STM32开发资料链接分享
Service asynchronous communication
Part V: STM32 system timer and general timer programming
【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
BFS realizes breadth first traversal of adjacency matrix (with examples)
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
Chapter II proxy and cookies of urllib Library
[batch dos-cmd command - summary and summary] - jump, cycle, condition commands (goto, errorlevel, if, for [read, segment, extract string]), CMD command error summary, CMD error
Deep learning environment configuration jupyter notebook
String comparison in batch file - string comparison in batch file
筑梦数字时代,城链科技战略峰会西安站顺利落幕
A brief history of deep learning (I)