当前位置:网站首页>[count] [combined number] value series
[count] [combined number] value series
2022-07-06 07:39:00 【Code chess】
Topic link :
https://ac.nowcoder.com/acm/contest/23481/B
Don't calculate the sequence a The value of , Because it is difficult to do it from this aspect .
Which values should be taken from the sequence to make the sequence a The value remains unchanged .
For three numbers to discuss :
- a i < a j < a k a_i < a_j <a_k ai<aj<ak or a i > a j > a k a_i >a_j>a_k ai>aj>ak when
Delete the number in the middle , The value of the sequence will not change . If the same number in the middle haskindividual , The number of cases is 2 k 2^k 2k - a i < a j > a k a_i < a_j >a_k ai<aj>ak or a i > a j < a k a_i >a_j<a_k ai>aj<ak when
Delete the middle value , The value of the sequence will change , So you can't delete . But if there are multiple equal values in the middle , Leave at least one value . If the number of equal numbers isk, Then the number of cases is 2 k − 1 2^k-1 2k−1( Remove the empty condition )
Next , Is to discuss the same number in the middle
Treat equal numbers as a connected block , Set to [ i , j ] [i,j] [i,j]
- If meet a i − 1 < a i = . . . = a j < a j + 1 a_{i-1}<a_i=...=a_j<a_{j+1} ai−1<ai=...=aj<aj+1 or a i − 1 > a i = . . . = a j > a j + 1 a_{i-1}>a_i=...=a_j>a_{j+1} ai−1>ai=...=aj>aj+1( And to satisfy i > 1 , j < n i>1,j<n i>1,j<n), Then interval [ i , j ] [i,j] [i,j] The number of can be deleted completely , Does not affect the value , Such a range contributes a lot to the answer 2 j − i + 1 2^{j-i+1} 2j−i+1 Kind of plan .
- Otherwise, the interval [ i , j ] [i,j] [i,j] The number of must keep one , Such a range contributes to the answer 2 j − i + 1 − 1 2^{j-i+1}-1 2j−i+1−1 Kind of plan . The answer is to multiply the contributions of all intervals .
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5, mod = 998244353;
vector<ll> fac(N);
void solve()
{
int n;
cin >> n;
vector<int> a(n);
for(auto &i : a) cin >> i;
ll res = 1;
for(int i = 0, j = 0; i < n; i++)
{
j = i;
while(j < n - 1 && a[j + 1] == a[i]) j++;
if(i - 1 >= 0 and j + 1 < n and (a[i - 1] < a[i] && a[i] < a[j + 1] || a[i - 1] > a[i] && a[i] > a[j + 1]))
res = res * fac[j - i + 1] % mod;
else res = res * (fac[j - i + 1] - 1) % mod;
i = j;
}
cout << res << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
fac[0] = 1;
for(int i = 1; i < N; i++)
fac[i] = fac[i - 1] * 2 % mod;
int t;
cin >> t;
// t = 1;
while(t--) solve();
return 0;
}
边栏推荐
- Jerry's general penetration test - do data transmission with app Communication [article]
- 861. Score after flipping the matrix
- Ble of Jerry [chapter]
- [online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
- Emo diary 1
- Simulation of Michelson interferometer based on MATLAB
- Google可能在春节后回归中国市场。
- Luogu p4127 [ahoi2009] similar distribution problem solution
- [MySQL learning notes 29] trigger
- 数字IC设计笔试题汇总(一)
猜你喜欢
![[computer skills]](/img/30/2a4506adf72eb4cb188dd64cce417d.jpg)
[computer skills]

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Generator Foundation

JMeter performance test steps practical tutorial

数字IC设计笔试题汇总(一)

861. Score after flipping the matrix
![When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]](/img/3e/3d5bff87995b4a9fac093a6d9f9473.png)
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Google may return to the Chinese market after the Spring Festival.

Relevant introduction of clip image
随机推荐
Typescript interface and the use of generics
Ble of Jerry [chapter]
Database addition, deletion, modification and query
上线APS系统,破除物料采购计划与生产实际脱钩的难题
opencv学习笔记九--背景建模+光流估计
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
The way to learn go (I) the basic introduction of go to the first HelloWorld
word设置目录
Simple and understandable high-precision addition in C language
Mise en œuvre du langage leecode - C - 15. Somme des trois chiffres - - - - - idées à améliorer
Generator Foundation
Position() function in XPath uses
TypeScript 函数定义
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
【mysql学习笔记30】锁(非教程)
[非线性控制理论]9_非线性控制理论串讲
word中如何删除某符号前面或后面所有的文字
The difference between TS Gymnastics (cross operation) and interface inheritance
Jerry needs to modify the profile definition of GATT [chapter]
