当前位置:网站首页>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 》
边栏推荐
- stop slave卡住--事务的事件没有复制完整
- Introduction and response to high concurrency
- STM32串口DAM接收253字节就死机原因排查
- 电路设计者常用的学习网站
- Jerry's fast touch does not respond [chapter]
- go 4種單例模式
- Mask R-CNN
- Easyclick, EC Quanlang network verification source code
- Webrtc audio and video capture and playback examples and mediastream media stream analysis
- Go multithreaded data search
猜你喜欢
![P7072 [CSP-J2020] 直播获奖](/img/bc/fcbc2b1b9595a3bd31d8577aba9b8b.png)
P7072 [CSP-J2020] 直播获奖

Jatpack------LiveData

地平线2022年4月最新方案介绍

Uniapp wechat login returns user name and Avatar

Dahua cloud native load balancing article - the passenger flow of small restaurants has increased

首批 | 腾讯云完成国内首个云原生安全成熟度评估

China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
![[LeetCode] 数组中的第K个最大元素【215】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 数组中的第K个最大元素【215】

数据标注典型案例,景联文科技如何助力企业搭建数据方案

LeetCode 968. Monitor binary tree
随机推荐
大一学习分享
Graphic view frame
Go语言sqlx库操作SQLite3数据库增删改查
Motivation du Protocole de chiffrement avancé AES
LeetCode 968. 监控二叉树
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
编辑卡顿
从2022年Q1财报看携程的韧性和远景
Chow-Liu Tree
[leetcode] reverse string [344]
Jerry's fast touch does not respond [chapter]
Jericho's thimble reaction when directly touching the prototype is abnormal [chapter]
Splunk audit setting
LeetCode 968. Monitor binary tree
Go condition variable
Golang's learning route
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
Stop slave is stuck -- the event of the transaction is not copied completely
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
https://ac.nowcoder.com/acm/contest/23481/B