이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <string.h>
#define N 200000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int aa[N], ii[N];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = aa[ii[j]] != aa[i_] ? aa[ii[j]] - aa[i_] : ii[j] - i_;
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int main() {
static int kk[N * 2 + 1];
static char marked[N];
int n, h, i, j, d, k;
long long ans;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &aa[i]);
ii[i] = i;
}
sort(ii, 0, n);
ans = 0;
for (i = 0; i < n; i = j) {
j = i + 1;
while (j < n && aa[ii[j]] == aa[ii[i]])
j++;
memset(marked, 0, n * sizeof *marked);
for (h = i; h < j; h++)
marked[ii[h]] = 1;
memset(kk, 0, (n * 2 + 1) * sizeof *kk);
d = n, kk[d] = 1, k = 0;
for (i = 0; i < n; i++)
if (marked[i]) {
k += kk[d];
ans += k;
d++, kk[d]++;
} else {
d--;
k -= kk[d];
ans += k;
kk[d]++;
}
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.c: In function 'main':
Main.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | 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... |