当前位置:网站首页>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;
}
边栏推荐
- I spring and autumn blasting-2
- 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?
- Jmeter性能测试:ServerAgent资源监控
- [JVM] operation instruction
- Install PHP extension spoole
- MySQL5.7的JSON基本操作
- 12 MySQL interview questions that you must chew through to enter Alibaba
- sql server char nchar varchar和nvarchar的区别
- Bugku's steganography
- 机器学习框架简述
猜你喜欢

Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking

How to paste the contents copied by the computer into mobaxterm? How to copy and paste

Anti shake and throttling

亿咖通科技通过ISO27001与ISO21434安全管理体系认证

Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)

Usage and usage instructions of JDBC connection pool

Huiyuan, 30, is going to have a new owner

JS knowledge points-01

Bugku's Ah Da

Your childhood happiness was contracted by it
随机推荐
Ionic Cordova project modification plug-in
Crud of MySQL
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
swiper. JS to achieve barrage effect
Mysql---- function
Select sort and bubble sort
Crud de MySQL
P6183 [USACO10MAR] The Rock Game S
F. Weights assignment for tree edges problem solving Report
Install PHP extension spoole
Bugku's steganography
P1451 求细胞数量/1329:【例8.2】细胞
The difference between SQL Server char nchar varchar and nvarchar
Easyocr character recognition
Example of lvgl display picture
Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
I spring web upload
[12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
Ctfshow web entry command execution
当代人的水焦虑:好水究竟在哪里?