File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
rozwiazania/xvii/etap1/tes Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ // Rozwiązanie zadania 'Test na inteligencję' z I etapu XVII OI.
2+ // Autor: Paweł Putra
3+ // Złożoność czasowa: O(s * log(m)), gdzie s to suma m_i z wejścia.
4+ // Złożoność pamięciowa: O(m).
5+
6+ #include < iostream>
7+ #include < vector>
8+ #include < algorithm>
9+ using namespace std ;
10+ constexpr int MAXN = 1'000'005 ;
11+ vector<int > occ[MAXN];
12+
13+ int32_t main () {
14+ ios_base::sync_with_stdio (0 );
15+ int m;
16+ cin >> m;
17+ for (int i = 1 ; i <= m; i++) {
18+ int x;
19+ cin >> x;
20+ occ[x].push_back (i);
21+ }
22+
23+ int n;
24+ cin >> n;
25+ while (n--) {
26+ int k;
27+ cin >> k;
28+
29+ int i = 0 ;
30+ bool jest_podciagiem = true ;
31+ while (k--) {
32+ int x;
33+ cin >> x;
34+
35+ if (jest_podciagiem) {
36+ auto it = upper_bound (occ[x].begin (), occ[x].end (), i);
37+ if (it == occ[x].end ()) {
38+ jest_podciagiem = false ;
39+ } else {
40+ i = *it;
41+ }
42+ }
43+ }
44+
45+ cout << (jest_podciagiem ? " TAK" : " NIE" ) << " \n " ;
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments