이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct node{
int s,e,m;
int s1,e1;
node *l,*r;
int num;
node(int S,int E){
s = S;
e = E;
m = (s + e)/2;
if(s == e){
s1 = s;
e1 = e;
num = 1;
}
else{
l = new node(s,m);
r = new node(m + 1,e);
num = l -> num + r -> num;
}
}
pair<pair<int,int>,int> query(int k){
if(s == e){
return {{s1,e1},s};
}
if(k > l -> num){
k -= l -> num;
return r -> query(k);
}
else{
return l -> query(k);
}
}
void deactivate(int i){
if(s == e){
num--;
return;
}
num--;
if(i <= m) l -> deactivate(i);
else r -> deactivate(i);
}
void update(int S, int E, int i){
if(s == e){
s1 = S;
e1 = E;
return;
}
if(i <= m) l -> update(S,E,i);
else r -> update(S,E,i);
}
}*root;
struct lode{
int s, e, m;
lode *l, *r;
int lazy = 0;
int v;
lode(int S, int E){
s = S;
e = E;
m = (s + e)/2;
lazy = 0;
if(s != e){
l = new lode(s,m);
r = new lode(m + 1, e);
v = 0;
}
else{
v = 0;
}
}
void update(int S, int E, int k){
if(S <= s && e <= E){
v += k;
lazy += k;
return;
}
if(S <= m) l -> update(S,E,k);
if(m < E) r -> update(S,E,k);
v = lazy + l -> v + r -> v;
}
int query(int i){
if(s == e) return v;
if(i <= m) return l -> query(i) + lazy;
else return r -> query(i) + lazy;
}
}*loot;
int rg[100100];
int prefix[100100];
vector<int> events[100100];
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
for(int i = 0; i < N - 1; i++){
if(K[i] > R) K[i] = 1;
else K[i] = 0;
}
root = new node(0,N-1);
for(int i = 0; i < C; i++){
int ns,ne;
ns = 1100100100;
ne = -1;
int pompf;
for(int j = 0; j <= E[i] - S[i]; j++){
pair<pair<int,int>,int> iii = root -> query(S[i] + 1);
ns = min(ns,iii.first.first);
ne = max(ne,iii.first.second);
if(j != E[i] - S[i]) root -> deactivate(iii.second);
else{
root -> update(ns,ne,iii.second);
}
}
S[i] = ns;
E[i] = ne;
}
prefix[0] = 0;
for(int i = 1; i < N; i++){
prefix[i] = prefix[i - 1] + K[i - 1];
}
for(int i = 0; i < C; i++){
if(S[i] > 0) rg[i] = prefix[E[i]] - prefix[S[i] - 1];
else rg[i] = prefix[E[i]];
}
loot = new lode(0, N - 1);
for(int i = 0; i < C; i++){
if(rg[i] == 0) loot -> update(S[i],E[i],1);
events[S[i]].push_back(i);
events[E[i] + 1].push_back(i);
}
pair<int,int> ans = {-1,-1};
for(int i = 0; i < N; i++){
if(i == 0){
ans = max(ans,{loot -> query(i),-i});
continue;
}
if(K[i - 1] == 1){
for(int j : events[i]){
if(S[j] == i){
rg[j]--;
if(rg[j] == 0){
loot -> update(S[j],E[j],1);
}
}
else{
rg[j]++;
if(rg[j] == 1){
loot -> update(S[j],E[j],-1);
}
}
}
}
ans = max(ans,{loot -> query(i),-i});
}
return -ans.second;
}
컴파일 시 표준 에러 (stderr) 메시지
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:129:13: warning: unused variable 'pompf' [-Wunused-variable]
129 | int pompf;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |