이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <bitset>
#include <array>
#include <deque>
#include <unordered_set>
// #pragma GCC optimize("O3")
int main()
{
    std::cin.tie(0)->sync_with_stdio(0);
    // O(N^2logN)
    int N,K,Q;
    std::cin >> N >> K >> Q;
    std::vector<int> A(N);
    for(auto& i : A) std::cin >> i;
    for(auto& i : A) i--;
    std::vector<std::pair<int,int>> xy(Q);
    for(auto&[x,y] : xy) std::cin >> x >> y;
    std::unordered_set<int> xs;
    for(auto&[x,y] : xy) {x--,y--;xs.insert(x);}
    std::vector<int> works_max(N);
    for(int x = 0; x < N; x++)
    {
        int l = x>0 ? std::max(x,works_max[x-1]) : 0;
        int r = N;
        bool p = 1;
        while(r-l>1)
        {
            int m = l+1;
            std::vector<std::vector<int>> reach(K);
            for(int i = x+1; i <= m; i++)
            {
                if(!(i%2)) reach[A[i]].push_back(A[i-1]); // O(N) total
                else reach[A[i-1]].push_back(A[i]);
            }
            
            bool b = 1;
            auto& g = reach;
            std::vector<int> inct(K);
            for(auto& i : g)
                for(auto& j : i) inct[j]++; // O(N)
            std::vector<int> S;
            for(int i = 0; i < K; i++) if(!inct[i]) S.push_back(i);
            std::vector<bool> seen(K);
            while(S.size()) // O(N)
            {
                auto n = S.back(); S.pop_back();
                for(auto ne : g[n])
                {
                    inct[ne]--;
                    if(!inct[ne]) S.push_back(ne);
                }
            }
            for(auto i : inct) b &= !i;
            
            if(b) l = m;
            else r = m;
            p = b;
        }
        works_max[x] = l;
        
        // bool g = 1;
        // for(int y = x+1; y < N; y++,g = !g)
        // {
        //     auto a = A[y];
        //     auto p = A[y-1];
        //     ltgt[g][a] |= ltgt[g][p];
        //     ltgt[g][a][p] = true;
        //     for(auto& i : ltgt[g]) if(i[a]) i |= ltgt[g][a]; 
        //     bool b = 0;
        //     for(int i = 0; i < K; i++) if((ltgt[0][i]<gt[1][i]).any() || ltgt[0][i][i] || ltgt[1][i][i]) b=1;
        //     if(b) break;
        //     works_max[x] = y;
        // }
    }
    for(auto i : works_max) std::cerr << i << "\n";
    for (auto[x,y] : xy)
    {
        std::cout << (works_max[x]>=y ? "YES" : "NO") << "\n";
    }
    
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:28:14: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   28 |         bool p = 1;
      |              ^| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |