Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <bitset>
- #include <vector>
- using namespace std;
- #define line bitmass
- const int MAXN=3030;
- const int bitmass_sz=95;
- const int size_of_int=32;
- typedef unsigned int uint;
- typedef unsigned long long ull;
- int N,K;
- struct bitmass{
- ull A[48];
- bitmass(){
- for (int i=0;i<=N/64;i++)
- A[i]=0;
- }
- void reset(){
- for (int i=0;i<=N/64;i++)
- A[i]=0;
- }
- void operator|=(const bitmass &b){
- for (int i=0;i<=N/64;i++)
- A[i]|=b.A[i];
- }
- void operator&=(const bitmass&b){
- for (int i=0;i<=N/64;i++)
- A[i]&=b.A[i];
- }
- void operator<<=(int k){ //pobitovo
- ull D[48]={}; int ks=N-k;
- ull q=ks/64; ks%=64;
- int n=N%64 ? N/64+1 : N/64;
- for (int i=0;i<n;i++){
- int k1=i+q; int k2=i+q+1;
- ull a=A[i]<<ks; ull b=A[i]>>(64-ks);
- if (k1<=47)D[k1]|=a;
- if (k2<=47)D[k2]|=b;
- }
- q=k/64; k%=64;
- n=N%64 ? N/64+1 : N/64;
- for (int i=n-1;i>=0;i--){
- int k1=i-q; int k2=i-q-1;
- ull a=A[i]>>k; ull b=A[i]<<(64-k);
- if (k1>=0)D[k1]|=a;
- if (k2>=0)D[k2]|=b;
- }
- for (int i=0;i<n;i++)
- A[i]=D[i];
- }
- void not(){
- for (int i=0;i<=N/64;i++)
- A[i]^=(1ll<<64)+((1ll<<64)-1);
- }
- bool operator[](int i){
- int k=i/64; i%=64;
- return (A[k]&(1ll<<i))!=0;
- }
- };
- inline void F(bitmass &b, int i, bool q){ //b[i]=q;
- int k=i/64; i%=64;
- if (b.A[k]&(1ll<<i) ^ q) b.A[k]^=(1ll<<i);
- }
- int c[MAXN],l[MAXN];
- line A[MAXN],C[MAXN],L;
- int main(){
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- cin>>N>>K;
- for (int i=0;i<N;i++){
- scanf("%d",&c[i]); c[i]--;
- F(C[c[i]],i,true);
- }
- for (int i=0;i<K;i++){
- scanf("%d",&l[i]);
- }
- for (int i=0;i<N;i++){
- F(L,i,l[c[i]]!=0);
- }
- line tmp;
- for (int i=1;i<=N/3;i++){
- for (int k1=0;k1<N;k1++){
- int k2=(k1+i)%N;
- int c1=c[k1],c2=c[k2];
- if (l[c1]==0 || l[c2]==0 || (c1==c2 && l[c1]<=1)) continue;
- tmp.reset();
- tmp|=C[c1];
- tmp|=C[c2];
- tmp.not();
- tmp&=L;
- if (c1==c2 && l[c1]==3)
- tmp|=C[c1];
- else if (c1!=c2){
- if (l[c1]>=2) tmp|=C[c1];
- if (l[c2]>=2) tmp|=C[c2];
- }
- F(tmp,k1,0); F(tmp,k2,0);
- tmp<<=k2;
- A[i]|=tmp;
- }
- }
- int ans=0;
- for (int i=1;i<=N/3;i++)
- for (int j=1;j<=N;j++){
- int q=N-i-j;
- if (q<=0 || !A[i][j]) continue;
- ans++;
- F(A[i],j,0); F(A[j],i,0); F(A[i],q,0); F(A[q],i,0); F(A[j],q,0); F(A[q],j,0);
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement