제출 #767097

#제출 시각아이디문제언어결과실행 시간메모리
767097Ahmed57마상시합 토너먼트 (IOI12_tournament)C++17
100 / 100
143 ms16352 KiB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int bit[100001];
void add(int e,int v){
    e++;
    while(e<=1e5){
        bit[e]+=v;
        e+=e&-e;
    }
}
long long sum(int e){
    e++;
    long long res = 0;
    while(e>=1){
        res+=bit[e];
        e -= e&-e;
    }
    return res;
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E){
    set<int> bst;
    for(int i = 0;i<N-1;i++){
        if(K[i]>R){
            bst.insert(i);
        }
    }
    ordered_set s;
    for(int i = 0;i<=N;i++){
        s.insert(i);
    }
    int ans[N] = {0};
    set<int> rem;
    for(int i = 0;i<N;i++)rem.insert(i);
    for(int i = 0;i<C;i++){
        int l = *s.find_by_order(S[i]) , r = *s.find_by_order(E[i]+1) - 1;
        if(l==r)continue;
        while(*s.upper_bound(l)<=r){
            s.erase(s.upper_bound(l));
        }
        auto it = bst.lower_bound(l);
        if(it!=bst.end()&&*it<=r-1){
            auto it2 = rem.lower_bound(l);
            while(it2!=rem.end()&&(*it2)<=r){
                ans[(*it2)] = sum((*it2));
                rem.erase(it2);
                it2 = rem.lower_bound(l);
            }
        }else{
            add(l,1);
            add(r+1,-1);
        }
    }
    for(auto i:rem){
        ans[i] = sum(i);
    }
    int lol = -1 , ind = 0;
    for(int i = 0;i<N;i++){
        if(lol<ans[i]){
            lol = ans[i];
            ind = i;
        }
    }
    return ind;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...