이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int maxA, N, M, b[200009], a[200009], l[100009], r[100009], c[100009], aib[200009];
vector < int > v[200009];
void U (int pos, int val)
{
while (pos <= N)
aib[pos] += val,
pos += pos - (pos & (pos - 1));
}
int Q (int pos)
{
int sum = 0;
while (pos)
sum += aib[pos],
pos &= pos - 1;
return sum;
}
int getVerdict (int S, int cntFlipped)
{
if (cntFlipped > M) return 0;
for (int i=1; i<=N; i++)
{
int newA = a[i] + cntFlipped;
if (newA < S) b[i] = 0;
else b[i] = (newA + 1 - S) / 2;
}
for (int i=1; i<=N; i++)
aib[i] = 0;
bool ok = 1;
int used = 0;
priority_queue < int > PQ;
for (int i=1; i<=N; i++)
{
for (auto r : v[i])
PQ.push (r);
int needed = max (0, b[i] - Q (N - i + 1));
if (needed > PQ.size ()) return 0;
while (needed --)
{
int r = PQ.top ();
PQ.pop (), used ++;
U (N - r + 1, +1);
}
}
return (used <= cntFlipped);
}
bool ok (int S)
{
if (S >= maxA) return 1;
if (getVerdict (S, maxA - S)) return 1;
if (getVerdict (S, maxA - S + 1)) return 1;
return 0;
}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d %d", &N, &M);
///N links: 1-2, 2-3, .., N-1
for (int i=1; i<=M; i++)
{
scanf ("%d %d %d", &l[i], &r[i], &c[i]);
if (l[i] > r[i]) swap (l[i], r[i]);
a[l[i]] ++, a[r[i]] --;
v[l[i]].push_back (r[i] - 1);
}
int p = 1, u = 0, mij, ras;
for (int i=1; i<=N; i++)
a[i] += a[i - 1], u = max (u, a[i]);
maxA = u;
while (p <= u)
{
mij = (p + u) >> 1;
if (ok (mij)) ras = mij, u = mij - 1;
else p = mij + 1;
}
printf ("%d\n", ras);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:67:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &N, &M);
~~~~~~^~~~~~~~~~~~~~~~~
arranging_tickets.cpp:71:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d %d", &l[i], &r[i], &c[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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |