Compare commits

...

4 Commits

Author SHA1 Message Date
3e421f198c update 2025-08-19 12:05:27 +08:00
321c58cc95 update 2025-08-19 10:35:00 +08:00
48ef07ec43 update 2025-08-19 10:03:05 +08:00
244f30692c update 2025-08-18 21:02:52 +08:00
3 changed files with 108 additions and 15 deletions

View File

@ -4,7 +4,7 @@
using ll = int64_t;
ll n;
ll n,q;
std::vector<ll> t;
std::vector<ll> v;
std::vector<ll> lazy;
@ -20,7 +20,6 @@ ll create(ll cur,ll l,ll r){
return t[cur];
}
ll rangeadd(ll cur, ll l, ll r, ll ql, ll qr, ll val) {
if (lazy[cur] != 0) {
t[cur] += lazy[cur] * (r - l + 1);
@ -61,7 +60,7 @@ ll rangequery(ll cur, ll l, ll r, ll ql, ll qr) {
}
int main(){
std::cin>>n;
std::cin>>n>>q;
t.resize((n+1)*4);
v.resize(n+1);
lazy.resize((n+1)*4);
@ -69,18 +68,17 @@ int main(){
std::cin>>v[i];
}
create(1, 1, n);
ll q;
std::cin>>q;
while(q--){
ll l, r, val;
std::cin>>l>>r>>val;
rangeadd(1, 1, n, l, r, val);
std::cout << t[1] << "\n";
}
std::cin>>q;
while(q--){
ll l, r;
std::cin>>l>>r;
std::cout << rangequery(1, 1, n, l, r) << "\n";
ll op;
std::cin>>op;
if(op==1){
ll x,y,z;
std::cin>>x>>y>>z;
rangeadd(1, 1, n, x, y, z);
}else{
ll x,y;
std::cin>>x>>y;
std::cout<<rangequery(1, 1, n, x, y)<<'\n';
}
}
}

44
src/8/18/sparsetable.cpp Normal file
View File

@ -0,0 +1,44 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <istream>
#include <vector>
using ll = int64_t;
std::vector<ll> lg2,nums;
std::vector<std::vector<ll>> st;
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
std::cin>>n;
ll q;
std::cin>>q;
nums.resize(n+1);
lg2.resize(1e5+5);
for(ll i=2;i<1e5+5;i++){
lg2[i]=lg2[i>>1]+1;
}
st.resize(n+1,std::vector<ll>(lg2[n]+2));
for(ll i=1;i<=n;i++){
std::cin>>nums[i];
st[i][0]=nums[i];
}
for(ll j=1;j<lg2[n]+2;j++){
for(ll i=1;i<=n && i+(1ll<<j)-1<=n;i++){
st[i][j]=std::max(st[i][j-1],st[i+(1ll<<(j-1))][j-1]);
}
}
while(q--){
ll l,r;
std::cin>>l>>r;
ll range = r-l+1;
ll k=lg2[range];
std::cout<<
std::max(st[l][k],st[r-(1ll<<k)+1][k])
<<"\n";
}
}

51
src/8/19/P1962.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <cstdint>
#include <iostream>
#include <vector>
using ll = int64_t;
const ll M = 1e9+7;
struct M22{
std::vector<std::vector<ll>> v{2,std::vector<ll>(2)};
M22 operator*(const M22&o){
M22 n;
n.v[0][0]=(v[0][0]*o.v[0][0]%M+v[0][1]*o.v[1][0]%M)%M;
n.v[0][1]=(v[0][0]*o.v[0][1]%M+v[0][1]*o.v[1][1]%M)%M;
n.v[1][0]=(v[1][0]*o.v[0][0]%M+v[1][1]*o.v[1][0]%M)%M;
n.v[1][1]=(v[1][0]*o.v[0][1]%M+v[1][1]*o.v[1][1]%M)%M;
return n;
}
M22&operator*=(const M22&o){
*this= *this * o;
return *this;
}
};
M22 fpow(M22 b,ll e){
M22 res;
res.v[0][0]=res.v[1][1]=1;
while(e){
if(e&1){
res*=b;
}
b*=b;
e>>=1;
}
return res;
}
int main(){
ll n;
std::cin>>n;
if(n<=2){
std::cout<<1<<'\n';
return 0;
}
n-=2;
M22 m{{{1,1},{1,0}}};
m=fpow(m, n);
std::cout<<
(m.v[0][0]+m.v[0][1])%M
<<'\n';
}