The meaning of problems: there is a length n of the sequence of a given number on a m number of positions as the ai have bi, the remaining number may be arbitrarily, so that ci represents ai prefix XOR and seeking $ \ sum_ {i = 1 } ^ {n} is the minimum value of $ CI, 1 <= m, bi <= n <= 1e9,0 <= ai <= 1e9
Vacancies in two ways: 1 after the position or vacancy, the vacancy will be able greedy 0; 2 position after already know, this time to consider each and every period of exclusive or 1 if you want the back, that is. s0 + 1 and determines the size of s1 (si represented by a binary number of i in the segment), to greedy (note that the first position before no gaps)
View Code
1 #include<bits/stdc++.h> 2 using namespace std; 3 struct ji{ 4 int id,k; 5 bool operator < (const ji &a){ 6 return id<a.id; 7 } 8 }a[100005]; 9 int n,m,s[2][101]; 10 long long ans; 11 int main(){ 12 scanf("%d%d",&n,&m); 13 for(int i=1;i<=m;i++)scanf("%d%d",&a[i].id,&a[i].k); 14 sort(a+1,a+m+1); 15 bool flag=(a[1].id==1); 16 a[++m].id=n+2; 17 for(int i=1;i<=m;i++){ 18 if (a[i].id==a[i-1].id+1)a[i].k^=a[i-1].k; 19 else{ 20 for(int j=0;j<31;j++){ 21 if (flag)ans+=s[1][j]*(1LL<<j); 22 else ans+=min(s[0][j]+1,s[1][j])*(1LL<<j); 23 s[0][j]=s[1][j]=0; 24 } 25 printf("%lld ",ans); 26 flag=0; 27 } 28 for(int j=0;j<31;j++)s[((a[i].k&(1<<j))>0)][j]++; 29 } 30 printf("%lld",ans); 31 }