当前位置:网站首页>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;
}
边栏推荐
- OSI 七层模型
- Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
- Bugku alert
- Crud of MySQL
- 把 ”中台“ 的思想迁移到代码中去
- 漫画:程序员不是修电脑的!
- I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
- Redis' transaction mechanism
- The difference between SQL Server char nchar varchar and nvarchar
- 亿咖通科技通过ISO27001与ISO21434安全管理体系认证
猜你喜欢

Appium自动化测试基础 — APPium基础操作API(二)

Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel

Thymeleaf uses background custom tool classes to process text

华为哈勃化身硬科技IPO收割机

Common MySQL interview questions

把 ”中台“ 的思想迁移到代码中去

爱可可AI前沿推介(7.5)

Creation and optimization of MySQL index

P1451 求细胞数量/1329:【例8.2】细胞

Huiyuan, 30, is going to have a new owner
随机推荐
Good article inventory
MySQL之CRUD
数学建模之层次分析法(含MATLAB代码)
R 熵权法计算权重及综合得分
go学习 ------jwt的相关知识
Go learning ----- relevant knowledge of JWT
30岁汇源,要换新主人了
lv_ font_ Conv offline conversion
Aike AI frontier promotion (7.5)
Hongmeng system -- Analysis from the perspective of business
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
12 MySQL interview questions that you must chew through to enter Alibaba
Reconnaissance des caractères easycr
Bugku's eyes are not real
Bubble sort, insert sort
SQL Server learning notes
I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
MySQL之CRUD
Ctfshow web entry command execution
MySQL----函数