-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10145.cpp
93 lines (73 loc) · 2.24 KB
/
10145.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll t; cin >> t;
cin.ignore(1000, '\n');
string str; getline(cin, str);
unordered_map<string, string> item_t;
unordered_map<string, bool> isBlocked;
unordered_map<string, string> prev;
unordered_map<string, bool> isX;
unordered_map<string, unordered_set<string>> hi;
unordered_map<string, unordered_set<string>> uni;
while(getline(cin, str)){
if(str == "#") continue;
if(str.empty()){
item_t.clear();
isBlocked.clear();
prev.clear();
hi.clear();
uni.clear();
cout << "\n";
continue;
}
vector<string> r;
stringstream ss(str); string temp;
while(ss >> temp){
r.push_back(temp);
}
string mode = r[0];
string trid = r[1];
string item = r[2];
if(isBlocked[trid]){
cout << "IGNORED\n";
continue;
}
// if(hi[item].find(trid) != hi[item].end() && hi[item].size()==1){
// }
if(mode == "X"){
bool c1 = uni[item].find(trid) != uni[item].end() && uni[item].size()==1;
bool c2 = uni[item].find(trid) == uni[item].end() && uni[item].size()==0;
if(c1||c2){
cout << "GRANTED\n";
}
else{
cout << "DENIED\n";
isBlocked[trid] = true;
continue;
}
hi[item].insert(trid);
uni[item].insert(trid);
continue;
}
else{
bool c1 = hi[item].find(trid) != hi[item].end() && hi[item].size()==1;
bool c2 = hi[item].find(trid) == hi[item].end() && hi[item].size()==0;
if(c1||c2){
cout << "GRANTED\n";
}
else{
cout << "DENIED\n";
isBlocked[trid] = true;
continue;
}
uni[item].insert(trid);
}
}
return 0;
}