2 solutions
-
1
using namespace std; int n, m, q; bitset<60000> s[30005], maxn, temp; int c; int main() { cin >> n >> m >> q;//第一行有三个数,依次表示集合的个数 n,集合元素的最大值 m 和操作次数 q for(int i = 1; i <= n; i++) { cin >> c;//第 2 到第 (n+1) 行,每行有若干个整数 for(int j = 1, x; j <= c; j++) { cin >> x;//第 (i+1) 行的整数描述集合 i 的元素 s[i][x] = 1; } } for(int i = 1; i <= m; i++) { maxn[i] = 1;//最大值 m } for(int i = 1; i <= q; i++) { int o, x, y; cin >> o >> x >> y;//接下来 q 行,每行三个整数 o,x,y 表示一次操作 if(o == 1) { s[x] <<= y; s[x] &= maxn; } if(o == 2) { s[x] >>= y; s[x] &= maxn; } if(o == 3) { temp = s[x] & s[y]; temp &= maxn; cout << temp.count() << endl; } if(o == 4) { temp = s[x] | s[y]; temp &= maxn; cout << temp.count() << endl; } if(o == 5) { temp = s[x] ^ s[y]; temp &= maxn; cout << temp.count() << endl; } } return 0; }
-
1
#include<bits/stdc++.h> using namespace std; int n, m, q; bitset<60000> s[30005], maxn, temp; int c; int main() { cin >> n >> m >> q;//第一行有三个数,依次表示集合的个数 n,集合元素的最大值 m 和操作次数 q for(int i = 1; i <= n; i++) { cin >> c;//第 2 到第 (n+1) 行,每行有若干个整数 for(int j = 1, x; j <= c; j++) { cin >> x;//第 (i+1) 行的整数描述集合 i 的元素 s[i][x] = 1; } } for(int i = 1; i <= m; i++) { maxn[i] = 1;//最大值 m } int o, x, y; for(int i = 1; i <= q; i++) { cin >> o >> x >> y;//接下来 q 行,每行三个整数 o,x,y 表示一次操作 switch (o) { case 1 : s[x] = s[x] << y; s[x] = s[x] & maxn; break; case 2 : s[x] = s[x] >> y; s[x] = s[x] & maxn; break; case 3 : temp = s[x] & s[y]; temp = temp & maxn; cout << temp.count() << endl; break; case 4 : temp = s[x] | s[y]; temp = temp & maxn; cout << temp.count() << endl; break; case 5 : temp = s[x] ^ s[y]; temp = temp & maxn; cout << temp.count() << endl; break; } } return 0; }
- 1
Information
- ID
- 1149
- Time
- 500ms
- Memory
- 512MiB
- Difficulty
- 8
- Tags
- # Submissions
- 22
- Accepted
- 6
- Uploaded By