当前位置:网站首页>[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;
}
边栏推荐
- 解决方案:智慧工地智能巡檢方案視頻監控系統
- Risk planning and identification of Oracle project management system
- TS 类型体操 之 extends,Equal,Alike 使用场景和实现对比
- Do you really think binary search is easy
- Google may return to the Chinese market after the Spring Festival.
- TypeScript void 基础类型
- 学go之路(一)go的基本介绍到第一个helloworld
- Methods for JS object to obtain attributes (. And [] methods)
- http缓存,强制缓存,协商缓存
- C # connect to SQLite database to read content
猜你喜欢

Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master

Google可能在春节后回归中国市场。
![[1. Delphi foundation] 1 Introduction to Delphi Programming](/img/14/272f7b537eedb0267a795dba78020d.jpg)
[1. Delphi foundation] 1 Introduction to Delphi Programming

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

Significance and measures of encryption protection for intelligent terminal equipment
![Ble of Jerry [chapter]](/img/ed/32a5d045af8876d7b420ae9058534f.png)
Ble of Jerry [chapter]

Do you really think binary search is easy
![DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist](/img/17/415e66d67afb055e94a966de25c2bc.png)
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist

opencv学习笔记九--背景建模+光流估计

How to delete all the words before or after a symbol in word
随机推荐
Word delete the contents in brackets
学go之路(二)基本类型及变量、常量
解决方案:智慧工地智能巡檢方案視頻監控系統
In the era of digital economy, how to ensure security?
Games101 Lesson 7 shading 1 Notes
链表面试题(图文详解)
Leecode-c language implementation -15 Sum of three ----- ideas to be improved
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
Related operations of Excel
Helm install Minio
洛谷P1836 数页码 题解
[cf gym101196-i] waif until dark network maximum flow
洛谷P4127 [AHOI2009]同类分布 题解
861. Score after flipping the matrix
实现精细化生产, MES、APS、ERP必不可少
The difference between TS Gymnastics (cross operation) and interface inheritance
Oracle column to row -- a field is converted to multiple rows according to the specified separator
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
Description of octomap averagenodecolor function
Bugku CTF daily question: do you want seeds? Blackmailed
