C1. Adjust The Presentation (Easy Version)
妈呀, 最难读懂的一道题(英语不好)
原题
思路
这道题读懂之后就是双指针. 不难想到只要之前出现过, 就一定可以展示出来, 唯一需要注意的时不能在a里有多余的科幻片
代码
#include <bits/stdc++.h>
#define int long long
using namespace std;const int N = 200010, mod = 1e9 + 7;int n, m, q, k, x, y, z, ans, t;
int w[N], f[N];
int a[N], b[N];void res(bool temp)
{if (temp) cout << "YA" << "\n";else cout << "TIDAK" << "\n";
}void solve()
{cin >> n >> m >> q;for (int i = 1; i <= n; i ++ ) cin >> a[i];for (int i = 1; i <= m; i ++ ) cin >> b[i];bool ans1 = true;unordered_set<int> mm;for (int i = 1, j = 1; j <= m;j ++ ){if (a[i] == b[j]){if (!mm.count(a[i])) mm.insert(a[i]);i ++;}if (!mm.count(b[j])){ans1 = false;break;}}res(ans1);
}signed main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T = 1;cin >> T;while (T -- ){solve();}
}