1 solutions
-
0
Guest MOD
-
0
考察 的应用
方法 : 思路: 对于每个人,维护一个集合,表示这个人能看哪些页面。 对于每次询问,看这个人的集合里有没有 这个人有没有最高权限即可。 做法: 对于操作 ,维护这个人能看的集合。 对于操作 ,直接记录这个人的最高权限。
#include <iostream> #include <set> using namespace std; #define N 200005 int vis[N]; // vis[x] -> 用户x是否是最高权限(1表示是,0表示否) set<int> st[N]; // st[x] -> 用户x能够查看的页面集合 int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // 加速输入输出 int n, m, q; cin >> n >> m >> q; while (q--) { int op, x, y; cin >> op; if (op == 1) { // 操作1:用户x添加可查看页面y cin >> x >> y; st[x].insert(y); } else if (op == 2) { // 操作2:设置用户x为最高权限 cin >> x; vis[x] = 1; } else { // 操作3:查询用户x是否能查看页面y cin >> x >> y; if (vis[x] || st[x].count(y)) { // 最高权限或页面在集合中 cout << "Yes\n"; } else { cout << "No\n"; } } } return 0; }方法2:
用一个数组或者用一个 存是否有最高权限,然后用一个 存 看 的权限是否可以访问 即可
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); using PII = pair<int, int>; void slove() { int n, m, q; cin >> n >> m >> q; map<int, int> mp; // 记录用户是否有最高权限 map<PII, int> mpp; // 记录用户可查看的页面 while (q--) { int op, x, y; cin >> op; if (op == 1) { // 操作1:用户x添加可查看页面y cin >> x >> y; mpp[{x, y}]++; } else if (op == 2) { // 操作2:设置用户x为最高权限 cin >> x; mp[x] = 1; } else { // 操作3:查询用户x能否查看页面y cin >> x >> y; if (mp[x] || mpp.count({x, y})) cout << "Yes\n"; else cout << "No\n"; } } } signed main() { IOS int tcase = 1; while (tcase--) { slove(); } return 0; }
- 1
Information
- ID
- 1468
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- (None)
- # Submissions
- 85
- Accepted
- 21
- Uploaded By