当前位置:网站首页>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 》
边栏推荐
- 首批 | 腾讯云完成国内首个云原生安全成熟度评估
- Uniapp wechat login returns user name and Avatar
- 世界环境日 | 周大福用心服务推动减碳环保
- Jielizhi, production line assembly link [chapter]
- Odoo13 build a hospital HRP environment (detailed steps)
- Go four singleton modes
- 手写ORM(对象关系映射)增删改查
- Qt QScrollArea
- Introduction and response to high concurrency
- Wait to solve the zombie process
猜你喜欢
Methods to solve the tampering of Chrome browser and edeg browser homepage
Boot actuator - Prometheus use
Webrtc audio and video capture and playback examples and mediastream media stream analysis
严守工期,确保质量,这家AI数据标注公司做到了!
Kubernetes uses the host name to allocate the pod on the specified node
Jatpack------LiveData
odoo13搭建医院HRP环境(详细步骤)
Baidu AI Cloud - create a face recognition application
mysql重置密码,忘记密码,重置root密码,重置mysql密码
最小生成树 Minimum Spanning Tree
随机推荐
成功改变splunk 默认URL root path
Hanging mirror security won four global infosec awards on rsac2022
Qt QScrollArea
Local dealers play the community group purchase mode and share millions of operations
P7072 [CSP-J2020] 直播获奖
Higher order operation of bits
To myself who is about to work
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
解决Chrome浏览器和Edeg浏览器主页被篡改的方法
Minimum spanning tree
[leetcode] number of palindromes [9]
【洛谷P1541】乌龟棋【DP】
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
Learning Websites commonly used by circuit designers
Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
加油站[问题分析->问题转换->贪心]
【喜欢的诗词】好了歌
Lc173. Binary search tree iterator
Analyse des données dossiers d'apprentissage - - analyse simple de la variance à facteur unique avec Excel
數據分析學習記錄--用EXCEL完成簡單的單因素方差分析