답안 #925336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925336 2024-02-11T13:04:58 Z anton 마상시합 토너먼트 (IOI12_tournament) C++17
49 / 100
1000 ms 4692 KB
#include<bits/stdc++.h>
using namespace std;

#define pii pair<int, int>

struct Tree{
  vector<int> tr;
  int bar= 1;
  void init(int _sz){
    while(bar<_sz){
      bar*=2;
    }
    tr.resize(2*bar, 0);
  }

  int get(int l, int r){
    l+=bar;
    r+=bar+1;


    int res= 0;
    for(; l<r; l/=2, r/=2){
      if(l%2==1){
        res= max(res, tr[l++]);
      }
      if(r%2==1){
        res= max(res, tr[--r]);
      }
    }
    return res;
  }

  void upd(){
    for(int i = bar-1; i>=1; i--){
      tr[i] = max(tr[i*2], tr[i*2+1]);
    }
  }
};

int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {

  vector<pii> affected;
  map<int, pii> is_set_to;

  for(int i = 0; i<N; i++){
    is_set_to[i] = pii(i, i);
  }
  for(int i = 0; i<C; i++){
    int l = S[i];
    int r=  E[i];

    auto it = is_set_to.begin();
    pii res= pii(0, 0);

    for(int j = 0; it!=is_set_to.end(); j++, ++it){
      if(j == l){
        res.first = it->second.first;
      }
      if(j==r){
        res.second = it->second.second;
      }
    }

    for(int j = res.first; j<=res.second; j++){
      is_set_to.erase(j);
    }
    is_set_to[res.first]= res;
    affected.push_back(res);
    //cout<<res.first<<" "<<res.second<<endl;
  }

  Tree tr;
  tr.init(N);

  pair<int, int> best = {0, 0};

  for(int i = 0; i<N; i++){
    //cout<<"pos "<<i<<endl;
    int cur= 0;
    for(int j = 0; j<i; j++){
      tr.tr[j+tr.bar] = K[j];
    }
    tr.tr[i+tr.bar] = R;
    for(int j = i+1; j<N; j++){
      tr.tr[j+tr.bar] = K[j-1];
    }
    tr.upd();

    for(int j = 0; j<C; j++){
      if(affected[j].first<=i && i<=affected[j].second){
        //cout<<"req "<<j<<" "<<"res "<<tr.get(affected[j].first, affected[j].second)<<endl;
        if(tr.get(affected[j].first, affected[j].second) == R){
          cur++;
          //cout<<"wins "<<j<<endl;
        }
      }
    }

    if(cur>best.first){
      best.first= cur;
      best.second= i;
    }
  }

  return best.second;


}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 348 KB Output is correct
2 Correct 939 ms 876 KB Output is correct
3 Correct 55 ms 600 KB Output is correct
4 Correct 240 ms 860 KB Output is correct
5 Correct 430 ms 816 KB Output is correct
6 Correct 113 ms 876 KB Output is correct
7 Correct 655 ms 856 KB Output is correct
8 Correct 388 ms 860 KB Output is correct
9 Correct 45 ms 856 KB Output is correct
10 Correct 152 ms 956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1056 ms 4692 KB Time limit exceeded
2 Halted 0 ms 0 KB -