-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdjust_The_Presentation_Easy_Version.cpp
More file actions
122 lines (106 loc) · 3.42 KB
/
Adjust_The_Presentation_Easy_Version.cpp
File metadata and controls
122 lines (106 loc) · 3.42 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// n people(1 to n) want to present the slideshow of m slides
// when a person in front if finished with presenting then he/she can go to any place without changing others' position
// there is another array b and is considered good if bi person presents ith slide
// in each query the boss will set b(si) = ti, where si = slide and ti = member
// for each q + 1 states tell if the array is good
// for easy version q = 0
// print YA if presentation is good else TIDAK
/* This is my initial solution
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Global setup for fast I/O
struct FastIO
{
FastIO()
{
ios_base::sync_with_stdio(false); // Disable C I/O synchronization
cin.tie(nullptr); // Untie cin and cout for faster input/output
}
} fast_io_setup; // This will be executed before main()
int main()
{
ll testcases;
cin >> testcases;
for (ll testcase = 0; testcase < testcases; testcase++)
{
ll n, m, q;
cin >> n >> m >> q;
vector<ll> a(n);
for (ll i = 0; i < n; i++)
{
cin >> a[i];
}
vector<ll> b(m);
for (ll i = 0; i < m; i++)
{
cin >> b[i];
}
// so traverse through each slide and maintain a vector of who has arrived to present
// now if b[i] is among anyone who has presented then it is good only
// if b[i] is not among anyone who has presented then it is not good
// Track who has presented by using a set for efficient look-up
unordered_set<ll> presented;
ll idx = 0;
presented.insert(a[idx]);
bool isGood = true;
idx++;
for (ll i = 0; i < m; i++)
{
if (presented.count(b[i]) == 0)
{
if(b[i] == a[idx]){
presented.insert(a[idx]);
idx++;
}
else{
isGood = false;
break;
}
}
}
cout << (isGood ? "YA" : "TIDAK") << endl;
}
}
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct FastIO {
FastIO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
} fast_io_setup;
int main() {
ll testcases;
cin >> testcases;
for (ll testcase = 0; testcase < testcases; testcase++) {
ll n, m, q;
cin >> n >> m >> q;
vector<ll> a(n);
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
vector<ll> b(m);
for (ll i = 0; i < m; i++) {
cin >> b[i];
}
// Track pending members who have presented before and can present again.
unordered_set<ll> pending;
bool isGood = true;
ll idx = 0; // Points to the next person in `a` who hasn't yet presented.
for (ll i = 0; i < m; i++) {
if (b[i] == a[idx]) { // `b[i]` is the next in the initial sequence `a`.
pending.insert(a[idx]); // Add to pending members.
idx++; // Move to the next person in `a`.
} else if (pending.count(b[i]) == 0) { // `b[i]` is neither the next person in `a` nor pending.
isGood = false;
break;
}
// If `b[i]` is in `pending`, it's already eligible to present.
}
cout << (isGood ? "YA" : "TIDAK") << endl;
}
}