当前位置:网站首页>Value sequence < detailed explanation of daily question >
Value sequence < detailed explanation of daily question >
2022-07-02 23:02:00 【CTGU-Yoghurt】
subject :
Topic link :
Ideas :
To do this problem, we must first understand a rule :
Here's the picture
Then we can discuss it in these two cases
Be the first 1 In this case :
Its number of schemes is 2 Of i-j+1 Power
Be the first 2 In this case :
Its number of schemes is 2 Of i-j+1 Power -1( Remove the case of completely deleting the intermediate value )
Then why is the number of schemes 2 Of i-j+1 Power Well ?
as follows
Code details :
#include<stdio.h>
#include<iostream>
using namespace std;
typedef long long ll;
ll a[(ll)2e5 + 6];
const int mod = 998244353;
ll qsm(ll x, ll y)// Fast power
{
ll ans = 1;
while (y)
{
if (y & 1) ans =ans*x%mod;
y =y>> 1;
x = x*x%mod;
}
return ans;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n; scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
ll ans = 1;
for (int i = 1; i <= n; i++)
{
int j = i;// Record the middle starting position
while (a[j + 1] == a[i]&&j<n) j++;// Take have
if (i >= 2 &&j<n&& ((a[j + 1]>a[i] && a[i]>a[i - 1]) || ((a[i] < a[i - 1]) && a[j + 1] < a[i])))
{
ans = ans*qsm(2, j - i + 1)%mod;
}// When satisfied i-1 To j+1 When the number in the range is single increase or single decrease ( And there can be equality in the middle ), Then for the case that all equal numbers can be deleted
else
{// The value in the middle is greater than the value on both sides or less than the value on both sides ( In this case, all intermediate values cannot be deleted ) And i be equal to 1 The situation of
ans =ans* (qsm(2, j - i+1)-1)%mod;
}
i = j;// Perform the next interval query
}
printf("%lld\n", ans);
}
return 0;
}
PS: Dew from tonight white , The moon is my hometown .____ Du Fu 《 On a moonlit night, I remember my brother 》
边栏推荐
- Lambda expression: an article takes you through
- 分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
- Learning Websites commonly used by circuit designers
- Analyse des données dossiers d'apprentissage - - analyse simple de la variance à facteur unique avec Excel
- Niuke network: maximum submatrix
- Jatpack------LiveData
- Boot actuator - Prometheus use
- Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
- [leetcode] number of palindromes [9]
- 严守工期,确保质量,这家AI数据标注公司做到了!
猜你喜欢
随机推荐
[LeetCode] 数组中的第K个最大元素【215】
【板栗糖GIS】arcscene—如何做出有高度的高程图
Chow-Liu Tree
STM32串口DAM接收253字节就死机原因排查
Splunk audit 的设定
go 条件变量
Qt QScrollArea
[Luogu p1541] tortoise chess [DP]
Easyclick, EC Quanlang network verification source code
Splunk audit setting
China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
MySQL查询附近的数据.并按距离进行排序.
Introduction and response to high concurrency
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
Freshman learning sharing
Mask R-CNN
Generics and reflection, this is enough
psnr,ssim,rmse三个指标的定量分析
How does Jerry test the wrong touch rate of keys [chapter]