#include<iostream>#include<cstring>#include<cstdio>#include<queue>#include<cstdlib>#include<cmath>#include<stack>#include<map>#include<string>#include<vector>#include<set>#include<bitset>#include<algorithm>#include<ctime>#include<tr1/unordered_map>usingnamespace std;#define ll long long#define lb long double#define INF 0x3f3f3f3f#define LINF 0x3f3f3f3f3f3f3f3f#define ull unsigned long long#define endl '\n'#define clr(a, b) memset(a, b, sizeof(a))#define lowbit(x) x & -x#define lson rt << 1, l, mid#define rson rt << 1 | 1, mid + 1, r#define PB push_back#define POP pop_back#define max_ll 9223372036854775807#define random(x) (rand()%x)//srand((ll)time(0));//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中//tr1::unordered_map<int,int>mp;constdouble eps =1e-14;constdouble pi =acos(-1);constint maxn =1e6+10;constint maxm =(maxn<<5)+5;const ll mod =1e9+7;constint hash_mod =19260817;int n, m;int a[maxn];
ll c[maxn];voidupdate(int x,int k){for(int i = x ; i <= n ; i +=lowbit(i)) c[i]+= k;}voidadd(int l,int r,int k){if(l > r)return;update(l, k);update(r +1,-k);}
ll query(int x){ ll ans =0;for(int i = x; i >0; i -=lowbit(i)) ans += c[i];return ans;}intmain(){scanf("%d %d",&n,&m);for(int i =1; i <= m ;++ i){scanf("%d",&a[i]);}for(int i =1; i < m ;++ i){int l = a[i], r = a[i+1];if(l == r)continue;if(l > r)swap(l, r);add(1, l -1, r - l);add(r +1, n, r - l);add(l, l, r -1);add(r, r, l);if(l +1<= r -1)add(l +1, r -1, r - l -1);//cout << query(n) << endl;}for(int i =1; i <= n ;++ i) cout <<query(i)<<' ';return0;}
#include<iostream>#include<cstring>#include<cstdio>#include<queue>#include<cstdlib>#include<cmath>#include<stack>#include<map>#include<string>#include<vector>#include<set>#include<bitset>#include<algorithm>#include<ctime>#include<tr1/unordered_map>usingnamespace std;#define ll long long#define lb long double#define INF 0x3f3f3f3f#define LINF 0x3f3f3f3f3f3f3f3f#define ull unsigned long long#define endl '\n'#define clr(a, b) memset(a, b, sizeof(a))#define lowbit(x) x & -x#define lson rt << 1, l, mid#define rson rt << 1 | 1, mid + 1, r#define PB push_back#define POP pop_back#define max_ll 9223372036854775807#define random(x) (rand()%x)//srand((ll)time(0));//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中//tr1::unordered_map<int,int>mp;constdouble eps =1e-14;constdouble pi =acos(-1);constint maxn =(1<<20)+10;constint maxm =(maxn<<5)+5;const ll mod =1e9+7;constint hash_mod =19260817;char s[maxn];int dp[maxn];intmain(){scanf("%s", s +1);int n =strlen(s +1);for(int i =1; i <= n ;++ i){int x =0;for(int j = i ; j <= n ;++ j){int y = s[j]-'a';if(x &(1<< y))break;//如果x和y有交集,及说明出现重复字符
x = x ^(1<< y);//相当于取并集
dp[x]= j - i +1;}}for(int i =0; i <20;++ i)for(int j =0; j <(1<<20);++ j)if((j &(1<< i))==0)//如果没有交集
dp[j ^(1<< i)]=max(dp[j ^(1<< i)], dp[j]);int ans =0;for(int i =0; i <(1<<20);++ i){
ans =max(ans, dp[i]+ dp[(1<<20)-1- i]);}
cout << ans;return0;}
枚举子集从大到小的方法
int S2, S=22;voidf(int x){int k =0, a[10]={0};while(x){
a[++k]= x %2;
x /=2;}for(int i = k ; i >=1;-- i) cout << a[i]; cout<<" ";}intmain(){// S是原集合,S1是子集,S2是S1关于S的补集for(int S1=S;S1!=0;S1=(S1-1)&S){
S2=S^S1;f(S);f(S1);f(S2);puts("");}return0;}