当前位置:网站首页>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 》
边栏推荐
- Qt QScrollArea
- 解决Chrome浏览器和Edeg浏览器主页被篡改的方法
- Lambda expression: an article takes you through
- Webrtc audio and video capture and playback examples and mediastream media stream analysis
- STM32之ADC
- 归并排序详解及应用
- antd组件upload上传xlsx文件,并读取文件内容
- `Usage of ${}`
- [chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM
- Odoo13 build a hospital HRP environment (detailed steps)
猜你喜欢
严守工期,确保质量,这家AI数据标注公司做到了!
LeetCode 968. Monitor binary tree
LeetCode 968. 监控二叉树
Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?
位的高阶运算
Boot actuator - Prometheus use
Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
Baidu AI Cloud - create a face recognition application
E-commerce system microservice architecture
[leetcode] reverse the word III in the string [557]
随机推荐
Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
Golang的学习路线
【洛谷P1541】乌龟棋【DP】
Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
用sentinel熔断比例阈值改不了,设置慢调用比例没效果
Go condition variable
數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Learning Websites commonly used by circuit designers
psnr,ssim,rmse三个指标的定量分析
WebRTC音视频采集和播放示例及MediaStream媒体流解析
go 4種單例模式
归并排序详解及应用
China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
[NPUCTF2020]ezlogin xPATH注入
Methods to solve the tampering of Chrome browser and edeg browser homepage
The kth largest element in the [leetcode] array [215]
数据分析学习记录--用EXCEL完成简单的单因素方差分析