POJ3378:Crazy Thairs(动态规划+线段树或树状数组+离散化+高精度)

该博客主要介绍了如何解决Crazy Thairs问题,这是一种涉及动态规划、线段树和高精度计算的算法挑战。给定一个不超过50000个元素且数值不超过10^9的序列,任务是找出所有满足特定条件的连续五数子序列。博主提供了两种解决方案,一种使用线段树,另一种使用树状数组,但后者在处理大数据时导致超时。文章通过实例解释了算法思路,并给出了相应的C++代码实现。
摘要由CSDN通过智能技术生成
Crazy Thairs
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 6092   Accepted: 1478

Description

These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ≤ N ≤ 50000) numbers, which  are no more than 109, Crazy Thair is a group of 5 numbers { i, j, k, l, m} satisfying:

1. 1 ≤ i < j < k < l < m  N
2. Ai < Aj < Ak < Al < Am

For example, in the sequence {2, 1, 3, 4, 5, 7, 6},there are four Crazy Thair groups: {1, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {1, 3, 4, 5, 7} and {2, 3, 4, 5, 7}.

Could you help Sempr to count how many Crazy Thairs in the sequence?

Input

Input contains several test cases. Each test case begins with a line containing a number N, followed by a line containing N numbers.

Output

Output the amount of Crazy Thairs in each sequence.

Sample Input

5
1 2 3 4 5
7
2 1 3 4 5 7 6
7
1 2 3 4 5 6 7

Sample Output

1
4
21

Source

MYCode:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 50010
int list[MAX];
int st[MAX];
struct bign

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值