mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-21 10:42:07 +00:00
update
This commit is contained in:
parent
993b5c017b
commit
50a8547e70
50
src/8/11/P11363.cpp
Normal file
50
src/8/11/P11363.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using ll = int64_t;
|
||||
|
||||
ll n,k,T,e;
|
||||
std::vector<std::vector<ll>> map;
|
||||
std::vector<ll> d,jc;
|
||||
const ll M = 1e9+7;
|
||||
|
||||
void solve(){
|
||||
std::cin>>n>>k;
|
||||
map.clear();
|
||||
map.resize(n+1);
|
||||
d.clear();
|
||||
d.resize(n+1);
|
||||
for(ll i=1;i<=n-1;i++){
|
||||
ll u,v;
|
||||
std::cin>>u>>v;
|
||||
map[u].push_back(v);
|
||||
map[v].push_back(u);
|
||||
d[u]++;
|
||||
d[v]++;
|
||||
}
|
||||
std::cin>>e;
|
||||
ll maxd=1;
|
||||
for(ll i=1;i<=n-1;i++){
|
||||
maxd=std::max(maxd,d[i]);
|
||||
}
|
||||
jc.clear();
|
||||
jc.resize(maxd+1);
|
||||
jc[1]=1;
|
||||
for(ll i=2;i<=maxd;i++){
|
||||
jc[i]=jc[i-1]*i%M;
|
||||
}
|
||||
ll ans=1;
|
||||
for(ll i=1;i<=n-1;i++){
|
||||
ans=(ans+jc[d[i]-1])%M;
|
||||
}
|
||||
std::cout<<(ans*2)%M<<'\n';
|
||||
}
|
||||
|
||||
int main(){
|
||||
std::cin>>T;
|
||||
while(T--){
|
||||
solve();
|
||||
}
|
||||
}
|
21
src/8/11/P11364.cpp
Normal file
21
src/8/11/P11364.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
using ll = int64_t;
|
||||
|
||||
ll n;
|
||||
std::vector<std::vector<ll>> m;
|
||||
|
||||
int main(){
|
||||
std::cin>>n;
|
||||
m.resize(n+1);
|
||||
for(ll i=1;i<=n-1;i++){
|
||||
ll u,v;
|
||||
std::cin>>u>>v;
|
||||
m[u].push_back(v);
|
||||
m[v].push_back(u);
|
||||
}
|
||||
|
||||
}
|
39
src/8/11/longest-substring-without-repeating-characters.cpp
Normal file
39
src/8/11/longest-substring-without-repeating-characters.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include<vector>
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int lengthOfLongestSubstring(std::string s) {
|
||||
|
||||
std::vector<int> last_pos(128, -1);
|
||||
int n = s.length();
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
}
|
||||
int max_len = 0;
|
||||
int left = 0;
|
||||
|
||||
for (int right = 0; right < n; ++right) {
|
||||
|
||||
char current_char = s[right];
|
||||
|
||||
if (last_pos[current_char] >= left) {
|
||||
left = last_pos[current_char] + 1;
|
||||
}
|
||||
|
||||
last_pos[current_char] = right;
|
||||
|
||||
max_len = std::max(max_len, right - left + 1);
|
||||
}
|
||||
return max_len;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
}
|
35
src/8/11/range-product-queries-of-powers.cpp
Normal file
35
src/8/11/range-product-queries-of-powers.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
using ll = int64_t;
|
||||
public:
|
||||
static inline ll lowbit(ll n){
|
||||
return n&(-n);
|
||||
}
|
||||
constexpr vector<int> productQueries(int n, vector<vector<int>>& queries) {
|
||||
const ll M=1e9+7;
|
||||
vector<ll> v;
|
||||
v.reserve(128);
|
||||
while(lowbit(n)){
|
||||
v.push_back(lowbit(n));
|
||||
n-=lowbit(n);
|
||||
}
|
||||
vector<int> ans;
|
||||
ans.reserve(queries.size());
|
||||
for(ll i=0;i<queries.size();i++){
|
||||
ll nans=1;
|
||||
for(ll j=queries[i][0];j<=queries[i][1];j++){
|
||||
nans=nans*v[j]%M;
|
||||
}
|
||||
ans.push_back(nans);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
}
|
@ -17,4 +17,7 @@ public:
|
||||
}
|
||||
return {0,0};
|
||||
}
|
||||
};
|
||||
};
|
||||
int main(){
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user