当前位置:网站首页>Value series solution report
Value series solution report
2022-07-05 15:25:00 【wch(】
Value series solution report
label : extremum Combinatorial number
source : Cattle from
Their thinking :
According to the topic definition , It is deduced that the value of a monotonic sequence is the absolute value of the difference between the first two ends , Then try to find the extreme point of the sequence first
To facilitate data processing, we use two arrays to count ,
a The array is included in the array after weight removal ( In this way, it is convenient to judge whether it is the extreme point )
b The array counts the number of original numbers
such as 1 3 3 4 4
Array a The values of are 1 3 4
Array b The values of are 1 2 2
Then consider the influence of extreme number and non extreme number on the final answer
For continuous same extremum ( Aforementioned a[3]) We must keep at least one ans * = 2 Of a[3] Time -1
All non extreme points can be retained or not ans * = 2*2
We use fast exponents to reduce complexity
Code implementation :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 1e5 + 8;
int a[N],c[N];
ll ksm(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) (ans *= a) %= mod;
(a *= a) %= mod;
b >>= 1;
}
return ans;
}
bool check(int i){
return (a[i] > a[i - 1] && a[i] > a[i + 1]) || (a[i] < a[i - 1] && a[i] < a[i + 1]);
}
int main() {
int t;
cin >> t;
while (t--) {
ll n;
ll ans = 1;
cin >> n;
int na=0,x;
memset(a,0,sizeof(a));
memset(c,0,sizeof(c));
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if(a[na]==x){
c[na]++;
}
else{
na++;
a[na]=x;
c[na]++;
}
}
int cnt=n;
if(na==1){
(ans *= ksm(2, c[1])-1) %= mod;
cout<<ans<<endl;
continue;
}
else{
(ans *= ksm(2, c[1])-1) %= mod;
(ans *= ksm(2, c[na])-1) %= mod;
cnt -= c[1]+c[na];
}
for (int i = 2; i <= na-1; i++) {
if (check(i)) {
cnt -= c[i];
(ans *= ksm(2, c[i])-1) %= mod;
}
}
(ans *= ksm(2, cnt)) %= mod;
cout << ans << endl;
}
return 0;
}
边栏推荐
- 数学建模之层次分析法(含MATLAB代码)
- 超越PaLM!北大碩士提出DiVeRSe,全面刷新NLP推理排行榜
- I include of spring and Autumn
- Severlet learning foundation
- Common redis data types and application scenarios
- Bugku's Eval
- Misc Basic test method and knowledge points of CTF
- Your childhood happiness was contracted by it
- Common MySQL interview questions
- Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
猜你喜欢
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
Transfer the idea of "Zhongtai" to the code
把 ”中台“ 的思想迁移到代码中去
1330:【例8.3】最少步数
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
[12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
I spring and autumn blasting-2
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
Super wow fast row, you are worth learning!
随机推荐
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
Misc Basic test method and knowledge points of CTF
The elimination strategy of redis
Redis distributed lock principle and its implementation with PHP (1)
The difference between abstract classes and interfaces in PHP (PHP interview theory question)
漫画:优秀的程序员具备哪些属性?
MySQL之CRUD
Bugku's Eval
lvgl 显示图片示例
B站做短视频,学抖音死,学YouTube生?
Thymeleaf uses background custom tool classes to process text
mapper.xml文件中的注释
Go learning ----- relevant knowledge of JWT
Leetcode: Shortest Word Distance II
Bugku's Ping
Super wow fast row, you are worth learning!
R 熵权法计算权重及综合得分
Number protection AXB function! (essence)
Ctfshow web entry explosion
1330: [example 8.3] minimum steps