# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
491087 |
2021-11-30T13:27:49 Z |
rainboy |
Tenis (COI19_tenis) |
C |
|
78 ms |
9232 KB |
#include <stdio.h>
#include <string.h>
#define N 100000
#define N_ (1 << 17) /* N_ = pow2(ceil(log2(N))) */
long long sum[N_ * 2], pref[N_ * 2]; int ii[N_], n_;
void pul(int i) {
int l = i << 1, r = l | 1;
sum[i] = sum[l] + sum[r];
if (pref[l] <= sum[l] + pref[r])
pref[i] = pref[l], ii[i] = ii[l];
else
pref[i] = sum[l] + pref[r], ii[i] = ii[r];
}
void build(int *aa, int *yy, int *zz, int n) {
int i;
n_ = 1;
while (n_ < n)
n_ <<= 1;
for (i = 0; i < n_; i++)
pref[n_ + i] = sum[n_ + i] = i < n ? yy[aa[i]] + zz[aa[i]] - i * 2 : 0, ii[n_ + i] = i;
for (i = n_ - 1; i > 0; i--)
pul(i);
}
void update(int i, int x) {
i += n_;
pref[i] = sum[i] = x;
while (i > 1)
pul(i >>= 1);
}
int main() {
static int aa[N], xx[N], yy[N], zz[N];
int n, q, i, j, a, b;
scanf("%d%d", &n, &q);
for (i = 0; i < n; i++) {
scanf("%d", &aa[i]), aa[i]--;
xx[aa[i]] = i;
}
for (i = 0; i < n; i++) {
scanf("%d", &a), a--;
yy[a] = i;
}
for (i = 0; i < n; i++) {
scanf("%d", &a), a--;
zz[a] = i;
}
build(aa, yy, zz, n);
while (q--) {
int t;
scanf("%d", &t);
if (t == 1) {
scanf("%d", &a), a--;
printf(xx[a] <= ii[1] ? "DA\n" : "NE\n");
} else {
int tmp;
scanf("%d%d%d", &t, &a, &b), a--, b--;
if (t == 1) {
i = xx[a], j = xx[b];
xx[a] = j, xx[b] = i;
update(xx[a], yy[a] + zz[a] - xx[a] * 2), update(xx[b], yy[b] + zz[b] - xx[b] * 2);
} else if (t == 2) {
tmp = yy[a], yy[a] = yy[b], yy[b] = tmp;
update(xx[a], yy[a] + zz[a] - xx[a] * 2), update(xx[b], yy[b] + zz[b] - xx[b] * 2);
} else {
tmp = zz[a], zz[a] = zz[b], zz[b] = tmp;
update(xx[a], yy[a] + zz[a] - xx[a] * 2), update(xx[b], yy[b] + zz[b] - xx[b] * 2);
}
}
}
return 0;
}
Compilation message
tenis.c: In function 'main':
tenis.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d", &n, &q);
| ^~~~~~~~~~~~~~~~~~~~~
tenis.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d", &aa[i]), aa[i]--;
| ^~~~~~~~~~~~~~~~~~~
tenis.c:48:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d", &a), a--;
| ^~~~~~~~~~~~~~~
tenis.c:52:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d", &a), a--;
| ^~~~~~~~~~~~~~~
tenis.c:59:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
tenis.c:61:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d", &a), a--;
| ^~~~~~~~~~~~~~~
tenis.c:66:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d%d%d", &t, &a, &b), a--, b--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
36 ms |
8120 KB |
Output is correct |
14 |
Correct |
37 ms |
8208 KB |
Output is correct |
15 |
Correct |
33 ms |
8088 KB |
Output is correct |
16 |
Correct |
34 ms |
8096 KB |
Output is correct |
17 |
Correct |
34 ms |
8088 KB |
Output is correct |
18 |
Correct |
32 ms |
8148 KB |
Output is correct |
19 |
Incorrect |
33 ms |
8092 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
9116 KB |
Output is correct |
2 |
Correct |
61 ms |
9132 KB |
Output is correct |
3 |
Correct |
61 ms |
9232 KB |
Output is correct |
4 |
Correct |
55 ms |
9120 KB |
Output is correct |
5 |
Correct |
62 ms |
9104 KB |
Output is correct |
6 |
Correct |
78 ms |
9132 KB |
Output is correct |
7 |
Correct |
62 ms |
9180 KB |
Output is correct |
8 |
Correct |
60 ms |
9188 KB |
Output is correct |
9 |
Correct |
57 ms |
9164 KB |
Output is correct |
10 |
Correct |
55 ms |
9152 KB |
Output is correct |
11 |
Correct |
61 ms |
9156 KB |
Output is correct |
12 |
Correct |
55 ms |
9156 KB |
Output is correct |
13 |
Correct |
76 ms |
9232 KB |
Output is correct |
14 |
Correct |
59 ms |
9156 KB |
Output is correct |
15 |
Correct |
59 ms |
9140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
36 ms |
8120 KB |
Output is correct |
14 |
Correct |
37 ms |
8208 KB |
Output is correct |
15 |
Correct |
33 ms |
8088 KB |
Output is correct |
16 |
Correct |
34 ms |
8096 KB |
Output is correct |
17 |
Correct |
34 ms |
8088 KB |
Output is correct |
18 |
Correct |
32 ms |
8148 KB |
Output is correct |
19 |
Incorrect |
33 ms |
8092 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |