Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.cpp
- * Author: Hrayr [HarHro94]
- * Problem: COCI contest#3
- * IDE: Visual C++
- */
- #include <algorithm>
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- #include <string>
- #include <vector>
- using namespace std;
- int n,m,bit[100007][32],val[32*100007],pos[32];
- vector<vector<pair<int,int> > > G;
- bool used[32*100007];
- void dfs(int u,int b);
- int main()
- {
- //freopen("input.txt","r",stdin);
- //freopen("output.txt","w",stdout);
- int i,j,k,i1,i2,cnt,type;
- long long res,num;
- scanf("%d %d", &n, &m);
- for(i=0;i<n;++i)
- {
- for(j=0;j<32;++j)
- {
- bit[i][j]=i*32+j;
- }
- }
- G.resize(32*n);
- for(i=0;i<m;++i)
- {
- scanf("%d", &type);
- if (type==1)
- {
- scanf("%d%d", &k, &cnt);
- --k;
- cnt%=32;
- if (cnt==0)
- {
- continue;
- }
- if (cnt==2)
- {
- cnt=2;
- }
- int p=0,tmp[32];
- for(j=0;j<32;++j)
- {
- tmp[j]=bit[k][(j+cnt)%32];
- }
- for(j=0;j<32;++j)
- {
- bit[k][j]=tmp[j];
- }
- }
- else
- {
- scanf("%d%d%lld", &i1, &i2, &res);
- --i1;--i2;
- int tmp[32];
- for(j=0;j<32;++j)
- {
- tmp[j]=((res>>j)&1);
- }
- for(j=0;j<32;++j)
- {
- G[bit[i1][j]].push_back(make_pair(bit[i2][j],tmp[j]));
- G[bit[i2][j]].push_back(make_pair(bit[i1][j],tmp[j]));
- }
- }
- }
- for(i=0;i<n;++i)
- {
- for(j=0;j<32;++j)
- {
- pos[bit[i][j]%32]=j;
- }
- for(j=31;j>=0;--j)
- {
- if (!used[bit[i][pos[j]]])
- {
- dfs(bit[i][pos[j]],0);
- }
- }
- }
- for(i=0;i<n;++i)
- {
- num=0;
- for(j=0;j<32;++j)
- {
- if (val[bit[i][j]]==1)
- {
- num+=(1LL<<(bit[i][j]%32));
- }
- }
- printf("%lld ", num);
- }
- printf("\n");
- return 0;
- }
- void dfs(int u,int b)
- {
- int i,willBe,to,type;
- val[u]=b;
- used[u]=1;
- for(i=0;i<G[u].size();++i)
- {
- to=G[u][i].first;
- type=G[u][i].second;
- if (type==0)
- {
- willBe=b;
- }
- else
- {
- willBe=1-b;
- }
- if (!used[to])
- {
- dfs(to,willBe);
- }
- else if (willBe!=val[to])
- {
- printf("-1\n");
- exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement