「CodePlus 2017 11 月赛」可做题

  这种题先二进制拆位,显然改的位置只有每一段确定的数的开头和结尾,只需要对于每一个可决策位置都尝试一下填1和0,然后取min即可。

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=;
const ll inf=1e15;
struct poi{int pos, w;}a[maxn];
int n, m, tot, xor0, xor1;
ll sum0, sum1, ans, ans0;
inline void read(int &k)
{
int f=; k=; char c=getchar();
while(c<'' || c>'') c=='-' && (f=-), c=getchar();
while(c<='' && c>='') k=k*+c-'', c=getchar();
k*=f;
}
inline bool cmp(poi a, poi b){return a.pos<b.pos;}
int main()
{
read(n); read(m);
for(int i=;i<=m;i++) read(a[i].pos), read(a[i].w);
sort(a+, a++m, cmp); m++;
for(int j=;j<;j++)
{
tot=xor0=sum0=xor1=ans0=;
sum1=(a[].pos==)?inf:;
for(int i=;i<=m;i++)
{
if(a[i].pos-!=a[i-].pos)
{
ans0=min(ans0+sum0, ans0+sum1+);
xor0=sum0=sum1=; xor1=;
}
xor0^=(a[i].w&(<<j))!=; xor1^=(a[i].w&(<<j))!=;
sum0+=xor0; sum1+=xor1;
}
ans+=ans0<<j;
}
printf("%lld\n", ans);
}
上一篇:「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡!(dij+bitset)


下一篇:[LOJ#6259]「CodePlus 2017 12 月赛」白金元首与独舞