이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 100100, MAXK = 2 * 100100, MAXA = 1e9 + 1e2;
int n, k, a[MAXN], b[MAXN];
long long ans = 0;
struct no
{
int cnt, mx;
no *l, *r;
no(int cnt = 0, int mx = 0) : cnt(cnt), mx(mx), l(nullptr), r(nullptr)
{}
};
inline int getcnt(no *n) { return (n ? n->cnt : 0); }
inline int getmx(no *n) { return (n ? n->mx : 0); }
no* upd(no* n, int pos, int val = 1, int beg = 1, int end = MAXA)
{
if(beg == end)
return new no(getcnt(n) + val, max(getmx(n), val));
no* ans = (n ? new no(*n) : new no());
int mid = (beg + end) >> 1;
if(pos <= mid)
ans->l = upd(ans->l, pos, val, beg, mid);
else
ans->r = upd(ans->r, pos, val, mid + 1, end);
ans->cnt = getcnt(ans->l) + getcnt(ans->r);
ans->mx = max(getmx(ans->l), getmx(ans->r));
return ans;
}
int getcnt(no* n, int pos, int beg = 1, int end = MAXA)
{
if(!n)
return 0;
int mid = (beg + end) >> 1;
if(pos <= mid)
return getcnt(n->l, pos, beg, mid) + getcnt(n->r);
return getcnt(n->r, pos, mid + 1, end);
}
int getmx(no* n, int a, int b, int beg = 1, int end = MAXA)
{
if(!n || b < beg || end < a)
return 0;
int mid = (beg + end) >> 1;
if(a <= beg && end <= b)
return getmx(n);
return max(getmx(n->l, a, b, beg, mid), getmx(n->r, a, b, mid + 1, end));
}
no *pseg[MAXK], *seg;
int main()
{
pseg[0] = seg = nullptr;
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; ++i)
scanf("%d %d", &a[i], &b[i]);
for(int i = 1, t; i <= k; ++i)
scanf("%d", &t), pseg[i] = upd(pseg[i - 1], t), seg = upd(seg, t, i);
for(int i = 1, swaps, j; i <= n; ++i)
{
j = getmx(seg, min(a[i], b[i]), max(a[i], b[i]) - 1), swaps = 0;
if(j)
swaps += (a[i] < b[i]);
swaps += getcnt(pseg[k], max(a[i], b[i]) - 1) - getcnt(pseg[j], max(a[i], b[i]) - 1);
ans += (swaps % 2 ? b[i] : a[i]);
}
printf("%lld\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~
fortune_telling2.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a[i], &b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:62:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &t), pseg[i] = upd(pseg[i - 1], t), seg = upd(seg, t, 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... |