Submission #866611

#TimeUsernameProblemLanguageResultExecution timeMemory
866611fanwenAlternating Heights (CCO22_day1problem1)C++17
Compilation error
0 ms0 KiB
/** * author : pham van sam * created : 26.10.2023 20:29:38 **/ #include <bits/stdc++.h> using namespace std; #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (int i = 0, _n = n; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; } const int MAXN = 3e3 + 5; int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], visit[MAXN], exist[MAXN]; vector <int> adj[MAXN]; void dfs(int u, int &ok) { visit[u] = 1; for (auto v : adj[u]) if(visit[v] < 2) { if(visit[v] == 1) { ok = 0; return; } else { dfs(v, ok); } } visit[u] = 2; } bool not_cycles(int l, int r) { fill(adj + 1, adj + K + 1, vector <int>()); fill(deg_in + 1, deg_in + K + 1, 0); fill(visit + 1, visit + K + 1, 0); fill(exist + 1, exist + K + 1, 0); FOR(i, l, r) { exist[A[i]] = 1; if(i & 1) { if(i + 1 <= r) { adj[A[i]].push_back(A[i + 1]); deg_in[A[i + 1]]++; } if(i - 1 >= l) { adj[A[i]].push_back(A[i - 1]); deg_in[A[i - 1]]++; } } // if(l == 2 && r == 4) { // if(i % 2 == 1 && i + 1 <= r) { // cout << A[i] << " " << A[i + 1] << '\n'; // } // if(i % 2 == 0 && i - 1 >= l) { // cout << A[i] << " " << A[i - 1] << '\n'; // } // } } FOR(i, 1, K) if(exist[i] && !deg_in[i]) { int oke = true; dfs(i, oke); if(!oke) return false; } FOR(i, 1, K) if(exist[i] && !visit[i]) return false; return true; } void you_make_it(void) { cin >> N >> K >> Q; FOR(i, 1, N) cin >> A[i]; int j = 1; FOR(i, 1, N) { while(j <= N && not_cycles(i, j)) ++j; res[i] = j; // cout << res[i] << " \n"[i == N]; } while(Q--) { int l, r; cin >> l >> r; cout << (res[l] <= r ? "NO\n" : "YES\n"); } } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.

Compilation message (stderr)

Main.cpp: In function 'void dfs(int, int&)':
Main.cpp:29:5: error: reference to 'visit' is ambiguous
   29 |     visit[u] = 1;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from Main.cpp:6:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
Main.cpp:25:48: note:                 'int visit [3005]'
   25 | int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], visit[MAXN], exist[MAXN];
      |                                                ^~~~~
Main.cpp:30:30: error: reference to 'visit' is ambiguous
   30 |     for (auto v : adj[u]) if(visit[v] < 2) {
      |                              ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from Main.cpp:6:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
Main.cpp:25:48: note:                 'int visit [3005]'
   25 | int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], visit[MAXN], exist[MAXN];
      |                                                ^~~~~
Main.cpp:31:12: error: reference to 'visit' is ambiguous
   31 |         if(visit[v] == 1) {
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from Main.cpp:6:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
Main.cpp:25:48: note:                 'int visit [3005]'
   25 | int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], visit[MAXN], exist[MAXN];
      |                                                ^~~~~
Main.cpp:38:5: error: reference to 'visit' is ambiguous
   38 |     visit[u] = 2;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from Main.cpp:6:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
Main.cpp:25:48: note:                 'int visit [3005]'
   25 | int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], visit[MAXN], exist[MAXN];
      |                                                ^~~~~
Main.cpp: In function 'bool not_cycles(int, int)':
Main.cpp:44:10: error: reference to 'visit' is ambiguous
   44 |     fill(visit + 1, visit + K + 1, 0);
      |          ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from Main.cpp:6:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
Main.cpp:25:48: note:                 'int visit [3005]'
   25 | int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], visit[MAXN], exist[MAXN];
      |                                                ^~~~~
Main.cpp:44:21: error: reference to 'visit' is ambiguous
   44 |     fill(visit + 1, visit + K + 1, 0);
      |                     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from Main.cpp:6:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
Main.cpp:25:48: note:                 'int visit [3005]'
   25 | int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], visit[MAXN], exist[MAXN];
      |                                                ^~~~~
Main.cpp:75:34: error: reference to 'visit' is ambiguous
   75 |     FOR(i, 1, K) if(exist[i] && !visit[i]) return false;
      |                                  ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from Main.cpp:6:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
Main.cpp:25:48: note:                 'int visit [3005]'
   25 | int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], visit[MAXN], exist[MAXN];
      |                                                ^~~~~