当前位置:网站首页>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 》
边栏推荐
- Learning Websites commonly used by circuit designers
- 海思3559万能平台搭建:在截获的YUV图像上画框
- Minimum spanning tree
- [leetcode] number of palindromes [9]
- mysql重置密码,忘记密码,重置root密码,重置mysql密码
- 容器化技术在嵌入式领域的应用
- 静态文件显示问题
- Niuke network: maximum submatrix
- [NPUCTF2020]ezlogin xPATH注入
- JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
猜你喜欢

Odoo13 build a hospital HRP environment (detailed steps)

海思3559万能平台搭建:在截获的YUV图像上画框

最小生成树 Minimum Spanning Tree

P1007 single log bridge

Local dealers play the community group purchase mode and share millions of operations
![[leetcode] reverse the word III in the string [557]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode] reverse the word III in the string [557]

Analyse des données dossiers d'apprentissage - - analyse simple de la variance à facteur unique avec Excel

从2022年Q1财报看携程的韧性和远景

Jatpack------LiveData

成功改变splunk 默认URL root path
随机推荐
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
静态文件显示问题
Qt QScrollArea
Distributed monitoring system ZABBIX
Qt QProgressBar详解
数据分析学习记录--用EXCEL完成简单的单因素方差分析
【板栗糖GIS】arcscene—如何做出有高度的高程图
Generics and reflection, this is enough
Jerry's fast touch does not respond [chapter]
Boot actuator - Prometheus use
分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
Qt QScrollArea
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
Pytorch training CPU usage continues to grow (Bug)
情感对话识别与生成简述
大一学习分享
全面解析分享购商业模式逻辑?分享购是如何赋能企业
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
泛型与反射,看这篇就够了
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
https://ac.nowcoder.com/acm/contest/23481/B