이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class RangeMax {
public:
vector<int>dat; int size_ = 1;
void init(int sz) {
while (size_ <= sz) size_ *= 2;
dat.resize(size_ * 2, 0);
}
void update(int pos, int x) {
pos += size_;
dat[pos] += x;
while (pos >= 2) {
pos >>= 1;
dat[pos] = max(dat[pos * 2], dat[pos * 2 + 1]);
}
}
int query_(int l, int r, int a, int b, int u) {
if (l <= a && b <= r) return dat[u];
if (b <= l || r <= a) return -(1 << 30);
int s1 = query_(l, r, a, (a + b) >> 1, u * 2);
int s2 = query_(l, r, (a + b) >> 1, b, u * 2 + 1);
return max(s1, s2);
}
int query(int l, int r) {
if (l >= r) return -(1 << 30);
return query_(l, r, 0, size_, 1);
}
};
class BIT {
public:
vector<int>bit; int size_ = 0;
void init(int sz) {
size_ = sz + 2;
bit.resize(size_ + 2, 0);
}
void add(int pos, int x) {
pos++;
while (pos <= size_) {
bit[pos] += x;
pos += (pos&-pos);
}
}
int sum(int pos) {
pos++; int s = 0;
while (pos >= 1) {
s += bit[pos]; pos -= (pos&-pos);
}
return s;
}
int arrays(int pos) {
int cl = 0, cr = size_ + 1, cm, minx = (1 << 30);
for (int i = 0; i < 20; i++) {
cm = (cl + cr) / 2;
int G = sum(cm);
if (G > pos) { minx = min(minx, cm); cr = cm; }
else { cl = cm; }
}
return minx;
}
};
vector<int>vec; int F[200009], EL[200009], ER[200009], cnts;
BIT Z; int dp[200009][22];
RangeMax Y;
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
Z.init(N + 1);
for (int i = 0; i < N; i++) { F[i] = i; EL[i] = i; ER[i] = i; cnts++; Z.add(i, 1); }
for (int i = 0; i < C; i++) {
vector<int>vec;
for (int j = S[i]; j <= E[i]; j++) vec.push_back(F[Z.arrays(j)]);
EL[cnts] = EL[vec[0]]; ER[cnts] = ER[vec[vec.size() - 1]];
for (int j = 0; j < vec.size(); j++) { dp[vec[j]][0] = cnts; F[EL[vec[j]]] = -1; Z.add(EL[vec[j]], -1); }
F[EL[cnts]] = cnts; Z.add(EL[cnts], 1);
cnts++;
}
dp[cnts - 1][0] = cnts;
dp[cnts][0] = cnts; EL[cnts] = 0; ER[cnts] = N;
Y.init(N + 1);
for (int i = 0; i < N; i++) Y.update(i, K[i]); Y.update(N, (1 << 30));
for (int i = 0; i < 21; i++) {
for (int j = 0; j <= cnts; j++) dp[j][i + 1] = dp[dp[j][i]][i];
}
int minx = -1, minid = 0;
for (int i = 0; i < N; i++) {
int tx = 0, cx = i;
for (int j = 21; j >= 0; j--) {
int ep = dp[cx][j];
bool flag = false;
if (ep < cnts) {
int el = EL[ep], er = ER[ep]; er--;
int G = Y.query(el, er + 1);
if (G > R) flag = false;
else flag = true;
}
if (flag == true) { tx += (1 << j); cx = ep; }
}
if (minx < tx) { minx = tx; minid = i; }
}
return minid;
}
컴파일 시 표준 에러 (stderr) 메시지
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:81:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < vec.size(); j++) { dp[vec[j]][0] = cnts; F[EL[vec[j]]] = -1; Z.add(EL[vec[j]], -1); }
~~^~~~~~~~~~~~
tournament.cpp:89:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = 0; i < N; i++) Y.update(i, K[i]); Y.update(N, (1 << 30));
^~~
tournament.cpp:89:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (int i = 0; i < N; i++) Y.update(i, K[i]); Y.update(N, (1 << 30));
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |