当前位置:网站首页>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 》
边栏推荐
猜你喜欢
随机推荐
Lc173. Binary search tree iterator
[羊城杯2020]easyphp
[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
分布式监控系统zabbix
Introduction and response to high concurrency
最小生成树 Minimum Spanning Tree
[LeetCode] 存在重复元素【217】
WebRTC音视频采集和播放示例及MediaStream媒体流解析
go 4种单例模式
静态文件显示问题
Baidu AI Cloud - create a face recognition application
数组进阶提高
Golang面试整理 三 简历如何书写
Qt QSplitter拆分器
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Minimum spanning tree
Go multithreaded data search
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
https://ac.nowcoder.com/acm/contest/23481/B![[leetcode] most elements [169]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)








