bitset用法详解 didiao233
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,col,q;
struct node{
bitset<32>tag;
bitset<32>condition;
}tree[N<<2];
int ls(int d){return (d<<1);}
int rs(int d){return ((d<<1)|1);}
void push_up(int d)
{
tree[d].condition=(tree[ls(d)].condition|tree[rs(d)].condition);
return ;
}
void push_down(int d)
{
if(tree[d].tag)
{
tree[ls(d)].condition=tree[ls(d)].tag=tree[d].tag;
tree[rs(d)].condition=tree[rs(d)].tag=tree[d].tag;
tree[d].tag.reset();
}
return ;
}
void build(int l,int r,int d)
{
if(l==r)
{
tree[d].condition.set(1);
return ;
}
int mid=(l+r)>>1;
build(l,mid,ls(d));
build(mid+1,r,rs(d));
push_up(d);
return ;
}
void change(int ,ql,int qr,int l,int r,int d)
{
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>col>>q;
build(1,n,1);
while(q--)
{
}
return 0;
}
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1000005;
int n,m,t,k,s[N],x,y,a[N],b[N],ans,tt[N];
void init()
{
for(int i=1;i<=n;++i)s[i]=i;
return ;
}
int find_s(int x)
{
if(s[x]==x)return x;
else return s[x]=find_s(s[x]);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>x>>y;
cin>>t>>k;
init();
for(int i=1;i<=m;++i)
{
cin>>a[i]>>b[i];
}
for(int i=1;i<=m;++i)
{
cin>>tt[i];
tt[i+m]=tt[i];
}
int l,r,u;
for(int i=1;i<=2*m;++i)
{
// l=find_s(a[tt[i]]),r=find_s(b[tt[i]]);/give @p minecraft:diamond_sword[minecraft:enchantments={sharpness:255}] 1
u=find_s(x);
ans+=t;
if(l!=u&&r!=u)continue;
if(l!=r)
{
s[l]=r;
}
if(find_s(x)==find_s(y))
{
ans=ans-t+k;
break;
}
}
cout<<ans;
return 0;
}#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000005;
int n,m,t,k,s[N],x,y,a[N],b[N],ans,tt[N];
void init()
{
for(int i=1;i<=n;++i)s[i]=i;
return ;
}
int find_s(int x)
{
if(s[x]==x)return x;
else return s[x]=find_s(s[x]);
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>x>>y;
cin>>t>>k;
init();
for(int i=1;i<=m;++i)
{
cin>>a[i]>>b[i];
}
for(int i=1;i<=m;++i)
{
cin>>tt[i];
tt[i+m]=tt[i];
}
int l,r,u;
for(int i=1;i<=2*m;++i)
{
l=find_s(a[tt[i]]),r=find_s(b[tt[i]]);
u=find_s(x);
ans+=t;
if(l!=u&&r!=u)continue;
if(l!=r)
{
s[l]=r;
}
if(find_s(x)==find_s(y))
{
ans=ans-t+k;
break;
}
}
cout<<ans;
return 0;
}#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000005;
int n,m,t,k,s[N],x,y,a[N],b[N],ans,tt[N];
map<int,map<int,int> >mp;
map<int,int>mp1;
signed main()
{
freopen("1.in","w",stdout);
srand(time(0));
n=rand()%1000000;
m=rand()%1000000;
k=rand()%1000000;
while(t<k)t=rand()%1000000;
cout<<n<<" "<<m<<" "<<t<<" "<<k<<"\n";
x=(rand()%n)+1;
while(x==y)y=(rand()%n)+1;
cout<<x<<" "<<y<<"\n";
for(int i=1;i<=m;++i)
{
int ss=0,tt=0;
while((mp[ss][tt]||mp[tt][ss])||ss==tt)
{
ss=(rand()%n)+1;
while(ss!=tt)tt=(rand()%n)+1;
}
mp[ss][tt]=1;
mp[tt][ss]=1;
cout<<ss<<" "<<tt<<"\n";
}
for(int i=1;i<=m;++i)
{
int tu;
while(mp1[tu])tu=(rand()%m)+1;
mp1[tu]=1;
cout<<tu<<"\n";
}
return 0;
}