mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-09-18 05:41:10 +00:00
Compare commits
No commits in common. "f8f53e255dd25e685e61673680bffdb9bd38f323" and "ee9687d88b5e49d780aea7a428c3cfb32bfcf91a" have entirely different histories.
f8f53e255d
...
ee9687d88b
@ -1,24 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
ll t,m;
|
|
||||||
std::cin>>t>>m;
|
|
||||||
std::vector<ll> dp(t+1);
|
|
||||||
for(ll i=1;i<=m;i++){
|
|
||||||
ll w,v;
|
|
||||||
std::cin>>w>>v;
|
|
||||||
for(ll j=w;j<=t;j++){
|
|
||||||
dp[j]=std::max(dp[j],dp[j-w]+v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<dp[t]<<"\n";
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
ll t;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>t;
|
|
||||||
std::vector<ll> a;
|
|
||||||
std::vector<bool> dp;
|
|
||||||
while(t--){
|
|
||||||
ll n;
|
|
||||||
std::cin>>n;
|
|
||||||
ll ans=n;
|
|
||||||
a.clear();
|
|
||||||
dp.clear();
|
|
||||||
a.resize(n+1);
|
|
||||||
|
|
||||||
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
std::cin>>a[i];
|
|
||||||
}
|
|
||||||
std::sort(a.begin()+1,a.begin()+1+n);
|
|
||||||
dp.resize(a[n]+1);
|
|
||||||
dp[0]=true;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
if(dp[a[i]]){
|
|
||||||
ans--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for(ll j=a[i];j<=a[n];j++){
|
|
||||||
dp[j]=dp[j]|dp[j-a[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<ans<<"\n";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
ll n,q;
|
|
||||||
std::cin>>n>>q;
|
|
||||||
std::vector<ll> lg(n+1);
|
|
||||||
for(ll i=2;i<=n;i++){
|
|
||||||
lg[i]=lg[i/2]+1;
|
|
||||||
// printf("lg2[%lld]=%lld\n",i,lg[i]);
|
|
||||||
}
|
|
||||||
std::vector<std::vector<ll>> bmax(n+1,std::vector<ll>(lg[n]+1)),bmin(n+1,std::vector<ll>(lg[n]+1));
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
std::cin>>bmax[i][0];
|
|
||||||
bmin[i][0]=bmax[i][0];
|
|
||||||
}
|
|
||||||
for(ll j=1;j<=lg[n];j++){
|
|
||||||
for(ll i=1;i+(1ll<<(j-1))<=n;i++){
|
|
||||||
bmax[i][j]=std::max(
|
|
||||||
bmax[i][j-1],
|
|
||||||
bmax[i+(1ll<<(j-1))][j-1]
|
|
||||||
);
|
|
||||||
bmin[i][j]=std::min(
|
|
||||||
bmin[i][j-1],
|
|
||||||
bmin[i+(1ll<<(j-1))][j-1]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(q--){
|
|
||||||
ll l,r;
|
|
||||||
std::cin>>l>>r;
|
|
||||||
ll range=r-l+1;
|
|
||||||
ll max = std::max(bmax[l][lg[range]],bmax[r-(1ll<<(lg[range]))+1][lg[range]]);
|
|
||||||
ll min = std::min(bmin[l][lg[range]],bmin[r-(1ll<<(lg[range]))+1][lg[range]]);
|
|
||||||
// printf("max=%lld, min=%lld\n",max,min);
|
|
||||||
std::cout<<max-min<<"\n";
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user