#include <iostream>
#include <vector>
#include <bitset>
#include <array>
#include <unordered_set>
constexpr int MAX_K = 3000;
int main()
{
std::cin.tie(0)->sync_with_stdio(0);
// O(N^2 + min(N,Q)KlogN)
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 : xs)
{
int l = x;
int r = N;
std::vector<std::vector<int>> reach[2] = {std::vector<std::vector<int>>(K),std::vector<std::vector<int>>(K)};
while(r-l>1)
{
int m = (r+l)/2;
for(int i = l+1; i <= m; i++)
{
reach[i%2][A[i]].push_back(A[i-1]);
reach[!(i%2)][A[i-1]].push_back(A[i]);
}
bool b = 1;
for (const auto& g : reach)
{
std::vector<int> inct(K);
for(auto& i : g)
for(auto& j : i) inct[j]++;
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())
{
auto n = S.back(); S.pop_back();
seen[n] = true;
for(auto ne : g[n])
{
inct[ne]--;
if(!inct[ne]) S.push_back(ne);
}
}
for(auto i : seen) b &= i;
}
if(b) l = m;
else
{
r = m;
for(int i = l+1; i <= m; i++)
{
reach[i%2][A[i]].pop_back();
reach[!(i%2)][A[i-1]].pop_back();
}
}
}
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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
11296 KB |
Output is correct |
2 |
Correct |
191 ms |
11356 KB |
Output is correct |
3 |
Correct |
194 ms |
11372 KB |
Output is correct |
4 |
Correct |
111 ms |
11088 KB |
Output is correct |
5 |
Correct |
123 ms |
11344 KB |
Output is correct |
6 |
Correct |
218 ms |
11272 KB |
Output is correct |
7 |
Correct |
192 ms |
11396 KB |
Output is correct |
8 |
Correct |
202 ms |
11360 KB |
Output is correct |
9 |
Correct |
215 ms |
11348 KB |
Output is correct |
10 |
Correct |
326 ms |
11864 KB |
Output is correct |
11 |
Correct |
573 ms |
12336 KB |
Output is correct |
12 |
Correct |
408 ms |
12260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
11352 KB |
Output is correct |
2 |
Correct |
136 ms |
11344 KB |
Output is correct |
3 |
Correct |
134 ms |
11348 KB |
Output is correct |
4 |
Correct |
117 ms |
12116 KB |
Output is correct |
5 |
Correct |
131 ms |
11272 KB |
Output is correct |
6 |
Correct |
137 ms |
11136 KB |
Output is correct |
7 |
Correct |
135 ms |
11344 KB |
Output is correct |
8 |
Correct |
137 ms |
11348 KB |
Output is correct |
9 |
Correct |
140 ms |
11600 KB |
Output is correct |
10 |
Correct |
174 ms |
12128 KB |
Output is correct |
11 |
Correct |
153 ms |
12112 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
789 ms |
764 KB |
Output is correct |
3 |
Correct |
801 ms |
800 KB |
Output is correct |
4 |
Correct |
26 ms |
760 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
543 ms |
720 KB |
Output is correct |
8 |
Correct |
915 ms |
808 KB |
Output is correct |
9 |
Execution timed out |
1035 ms |
812 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
11296 KB |
Output is correct |
2 |
Correct |
191 ms |
11356 KB |
Output is correct |
3 |
Correct |
194 ms |
11372 KB |
Output is correct |
4 |
Correct |
111 ms |
11088 KB |
Output is correct |
5 |
Correct |
123 ms |
11344 KB |
Output is correct |
6 |
Correct |
218 ms |
11272 KB |
Output is correct |
7 |
Correct |
192 ms |
11396 KB |
Output is correct |
8 |
Correct |
202 ms |
11360 KB |
Output is correct |
9 |
Correct |
215 ms |
11348 KB |
Output is correct |
10 |
Correct |
326 ms |
11864 KB |
Output is correct |
11 |
Correct |
573 ms |
12336 KB |
Output is correct |
12 |
Correct |
408 ms |
12260 KB |
Output is correct |
13 |
Correct |
133 ms |
11352 KB |
Output is correct |
14 |
Correct |
136 ms |
11344 KB |
Output is correct |
15 |
Correct |
134 ms |
11348 KB |
Output is correct |
16 |
Correct |
117 ms |
12116 KB |
Output is correct |
17 |
Correct |
131 ms |
11272 KB |
Output is correct |
18 |
Correct |
137 ms |
11136 KB |
Output is correct |
19 |
Correct |
135 ms |
11344 KB |
Output is correct |
20 |
Correct |
137 ms |
11348 KB |
Output is correct |
21 |
Correct |
140 ms |
11600 KB |
Output is correct |
22 |
Correct |
174 ms |
12128 KB |
Output is correct |
23 |
Correct |
153 ms |
12112 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
789 ms |
764 KB |
Output is correct |
27 |
Correct |
801 ms |
800 KB |
Output is correct |
28 |
Correct |
26 ms |
760 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
484 KB |
Output is correct |
31 |
Correct |
543 ms |
720 KB |
Output is correct |
32 |
Correct |
915 ms |
808 KB |
Output is correct |
33 |
Execution timed out |
1035 ms |
812 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |