Submission #1154388

#TimeUsernameProblemLanguageResultExecution timeMemory
1154388SofiatpcJousting tournament (IOI12_tournament)C++20
17 / 100
1095 ms584 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define sc second
typedef pair<int,int> pii;
typedef tree< pii, null_type, less<pii>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int MAXN = 1e5+5;
int v[MAXN];

int GetBestPosition(int n, int c, int r, int *K, int *s, int *e) {
  v[0] = r;
  for(int i = 0; i < n-1; i++)v[i+1] = K[i];

  int ans = 0, pos = 0;
  for(int i = 0; i < n; i++){
    if(i != 0)swap(v[i-1],v[i]);

    ordered_set st;
    for(int j = 0; j < n; j++)st.insert({j,v[j]});

    int cur = 0;
    for(int j = 0; j < c; j++){
      int x = e[j]-s[j], mx = 0, l;

      for(int k = 0; k <= x; k++){
        auto it = st.find_by_order(s[j]);
        if(k == 0)l = it->fi;
        mx = max(mx,it->sc);
        st.erase(it);
      }
      if(mx == r)cur++;
      st.insert({l, mx});
    }
    if(ans < cur){ans = cur; pos = i;}
    else if(ans == cur && pos > i)pos = i;
  }

  return pos;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...