其他分享
首页 > 其他分享> > 2460: [BeiJing2011]元素

2460: [BeiJing2011]元素

作者:互联网

总结:线性基插入;

https://www.lydsy.com/JudgeOnline/problem.php?id=2460

#include<bits/stdc++.h>
using namespace std;

#define sfi(i) scanf("%d",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-8
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

//----------------------------------------------------------
const int BufferSize = 1 << 16;
char buffer[BufferSize], *head, *tail;
inline char Getchar() {
    if (head == tail) {
        int l = fread(buffer, 1, BufferSize, stdin);
        tail = (head = buffer) + l;
    }
    return *head++;
 }
inline ll read() {
    ll x = 0, f = 1;char c = Getchar();
    for (;!isdigit(c);c = Getchar()) if (c == '-') f = -1;
    for (;isdigit(c);c = Getchar()) x = x * 10 + c - '0';
    return x * f;
 }
//----------------------------------------------------------

const int maxn=1e5+9;

struct node
{
    ll id,val;
    bool operator < (const node &b)const
    {
        return val>b.val;
    }
}a[maxn];
ll p[100];
int main()
{
    //FAST_IO;

    //freopen("input.txt","r",stdin);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].id>>a[i].val;
    }
    sort(a+1,a+n+1);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=62;j>=0;j--)
        {
            if(!(a[i].id>>j)) continue;
            if(!p[j])
            {
                p[j]=a[i].id;
                break;
            }
            a[i].id^=p[j];
        }
        if(a[i].id) ans+=a[i].val;
    }
    cout<<ans<<endl;
    //1 for(int i=62;i>=0;i--) if((ans^p[i])>ans) ans=ans^p[i];//从线性基中得到最大值

    return 0;
}

 

标签:2460,val,int,元素,long,ans,BeiJing2011,id,define
来源: https://blog.csdn.net/weixin_39132605/article/details/95902098