#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define all(lpv) lpv.begin(), lpv.end()
#define fi first
#define se second
#define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
using namespace std;
typedef pair<int,int> pii;
const int N = 1e6 + 5;
const int oo = 1e9;
int n, f[N], k, q, a[N], flag[N], deg[N], id[N];
vector<int> p[N];
int demin, in[N], en[N];
void dfs(int u) {
in[u] = ++demin;
for(auto j : p[u]) {
if(!in[j]) {
dfs(j);
}
}
en[u] = demin;
}
bool kt(int u,int v) {
return in[u] <= in[v] && in[v] <= en[u];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")) {
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n >> k >> q;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++) {
f[i] = i;
int l = i + 1, r = n, mid;
// if(i != 1) continue;
while(l <= r) {
mid = (l + r) / 2;
// cerr << mid << " check\n";
for(int j = 1; j <= k; j ++) {
id[j] = j, flag[j] = 0, p[j].clear(), deg[j] = 0;
in[j] = en[j] = 0;
}
demin = 0;
for(int j = i; j < mid; j ++) {
if(j % 2 == i % 2) { // >
p[a[j]].push_back(a[j + 1]);
} else {
p[a[j + 1]].push_back(a[j]);
}
}
for(int h = 1; h <= k; h ++) {
int j = id[h];
if(in[j]) continue;
dfs(j);
}
bool ff = true;
for(int j = 1; j <= k; j ++) {
for(auto h : p[j]) {
if(kt(h, j)) {
ff = false;
break;
}
}
if(!ff) break;
}
if(ff) f[i] = mid, l = mid + 1;
else r = mid - 1;
}
}
while(q--) {
int l, r; cin >> l >> r;
if(f[l] < r) cout << "NO\n";
else cout << "YES\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen(task ".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | freopen(task ".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |