This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#define N 3000
#define M 3000
int *ej[N], eo[N], fo[N], n;
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int ii[M], m;
int check(int l, int r) {
static int qu[N];
int cnt, h, i, j, o;
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]), eo[i] = 0, fo[i] = 0;
for (h = l; h < r; h++)
if (h % 2 == 0)
append(ii[h], ii[h + 1]), fo[ii[h + 1]]++;
else
append(ii[h + 1], ii[h]), fo[ii[h]]++;
cnt = 0;
for (i = 0; i < n; i++)
if (fo[i] == 0)
qu[cnt++] = i;
for (h = 0; h < cnt; h++) {
i = qu[h];
for (o = eo[i]; o--; ) {
j = ej[i][o];
if (--fo[j] == 0)
qu[cnt++] = j;
}
}
for (i = 0; i < n; i++)
free(ej[i]);
return cnt == n;
}
int main() {
static int rr[M];
int q, h, l, r;
scanf("%d%d%d", &m, &n, &q);
for (h = 0; h < m; h++)
scanf("%d", &ii[h]), ii[h]--;
for (l = 0, r = 0; l < m; l++) {
while (r < m && check(l, r))
r++;
rr[l] = r;
}
while (q--) {
scanf("%d%d", &l, &r), l--, r--;
printf(r < rr[l] ? "YES\n" : "NO\n");
}
return 0;
}
Compilation message (stderr)
Main.c: In function 'append':
Main.c:12:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
12 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
Main.c: In function 'main':
Main.c:51:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d%d%d", &m, &n, &q);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:53:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d", &ii[h]), ii[h]--;
| ^~~~~~~~~~~~~~~~~~~
Main.c:60:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d%d", &l, &r), l--, r--;
| ^~~~~~~~~~~~~~~~~~~~~
# | 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... |