当前位置:网站首页>Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
2022-07-03 22:08:00 【seez】

Because it is a subsequence problem , You can find that there are two choices for each element , Choose or not
So there may be 2^n Seed sequence , If you enumerate all the intervals , And find out their maximum and minimum , The time complexity is O(n*2^n)
Because only the maximum and minimum values of each interval are used , So we just need to enumerate the maximum and minimum values , At the same time, we found that because it is a subsequence , Don't care about his position , Because as the most valuable position, it can be arbitrary , So you can sort
So for every point , There are all cases as the maximum and all cases as the minimum , Because the product is , You can list the number of times he takes as the maximum value p, obtain
And the number of times as the minimum q, obtain
, Don't worry about the other maximum value matching him
because 2^p and 2^q The time complexity as a power is too high , So we need to use Euler power reduction
number theory --- Euler theorem , Fast power inverse _qq12323qweeqwe The blog of -CSDN Blog
Due to Fermat's small lemma :
Content : Existence prime p,a And p Coprime
== 
that q == (p-1)u +v , because a^(p-1)u ==1, So there is one left a^v, So we just need to a Take a module to the power of , You can achieve the effect of power reduction
summary :
- The nature of the topic , Subsequence + The most value , Find that you don't need to care about the location of elements , You can sort in ascending order
- A number position i, As a minimum
As the maximum value 
- The product of a number
, Carry out Euler power reduction
#include <iostream>
#include <algorithm>
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int a[N];
typedef long long ll;
ll qmi(ll a,ll b,ll mod)
{
ll res=1;
while(b)
{
if(b&1)
res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
ll res=1;
sort(a+1,a+1+n); // The sequence needs to be rearranged
for(int i=1;i<=n;i++)
{
// As a minimum
res=res*qmi(a[i],qmi(2,i-1,mod-1)+qmi(2,n-i,mod-1),mod)%mod;
}
cout<<res;
return 0;
}边栏推荐
- 国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
- Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
- Electronic tube: Literature Research on basic characteristics of 6j1
- [dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
- Getting started with DOM
- 2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
- Base ring tree Cartesian tree
- Netfilter ARP log
- Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
- [dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
猜你喜欢

Common SQL sets

Imitation Netease cloud music applet

Persistence of Nacos

Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)

The post-90s resigned and started a business, saying they would kill cloud database

A little understanding of GSLB (global server load balance) technology

The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation

Redis concludes that the second pipeline publishes / subscribes to bloom filter redis as a database and caches RDB AOF redis configuration files

treevalue——Master Nested Data Like Tensor

Collection | pytoch common loss function disassembly
随机推荐
Tkinter Huarong Road 4x4 tutorial III
Conditional statements of shell programming
Plug - in Oil Monkey
regular expression
Kali2021.4a build PWN environment
Memory analyzer (MAT)
DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
Luogu deep foundation part 1 Introduction to language Chapter 6 string and file operation
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
Covariance
内存分析器 (MAT)
DR-NAS26-Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-5GHz-high-power-Mini-PCIe-Wi-Fi-Module
Minio deployment
treevalue——Master Nested Data Like Tensor
Nacos common configuration
Cognitive fallacy: what is Fredkin's paradox
(5) User login - services and processes - History Du touch date stat CP
2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
As the maximum value 
, Carry out Euler power reduction