Advertisement
Guest User

IOI 2012 Tournament

a guest
Jan 5th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <ext/pb_ds/assoc_container.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. typedef long long ll;
  9. typedef vector<int> vi;
  10. typedef pair<int, int> pii;
  11. template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  12.  
  13. #define FOR(i, a, b) for (int i = a; i < (b); i++)
  14. #define F0R(i, a) for (int i = 0; i < (a); i++)
  15. #define FORd(i, a, b) for (int i = (b) - 1, i >= a; i--)
  16. #define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
  17.  
  18. #define sz(x) (int)(x).size()
  19. #define mp make_pair
  20. #define pb emplace_back
  21. #define f first
  22. #define s second
  23. #define lb lower_bound
  24. #define ub upper_bound
  25. #define all(x) x.begin(), x.end()
  26.  
  27. const int MOD = 1000000007;
  28.  
  29. void fast_io(){
  30.     ios_base::sync_with_stdio(0);
  31.     cin.tie(NULL);
  32.     cout.tie(NULL);
  33. }
  34.  
  35. int ranks[100005];
  36. vector<pii> games;
  37. Tree<pii> players;
  38. vector<pii> won_games;
  39. int diff[100005];
  40.  
  41. template<class T, int SZ> struct RMQ {
  42.     T stor[SZ][32-__builtin_clz(SZ)];
  43.    
  44.     T comb(T a, T b) {
  45.         return max(a,b);
  46.     }
  47.    
  48.     void build(vector<T>& x) {
  49.         F0R(i,sz(x)) stor[i][0] = x[i];
  50.         FOR(j,1,32-__builtin_clz(SZ)) F0R(i,SZ-(1<<(j-1)))
  51.             stor[i][j] = comb(stor[i][j-1],stor[i+(1<<(j-1))][j-1]);
  52.     }
  53.    
  54.     T query(int l, int r) {
  55.         int x = 31-__builtin_clz(r-l+1);
  56.         return comb(stor[l][x],stor[r-(1<<x)+1][x]);
  57.     }
  58. };
  59.  
  60. RMQ<int, 100005> DS;
  61.  
  62. int main(){
  63.     int N, C, R; cin >> N >> C >> R;
  64.    
  65.     vector<int> v;
  66.    
  67.     for (int i = 0; i < N - 1; i++){
  68.         cin >> ranks[i];
  69.         v.push_back(ranks[i]);
  70.         players.insert(pii(i, i));
  71.     }
  72.    
  73.     DS.build(v);
  74.    
  75.     players.insert(pii(N - 1, N - 1));
  76.    
  77.     for (int i = 0; i < C; i++){
  78.        
  79.         int S, E; cin >> S >> E;
  80.         pii k = *players.find_by_order(S);
  81.         pii r = *players.find_by_order(E);
  82.        
  83.         games.push_back(pii(k.first, r.second));
  84.        
  85.         for (int i = S; i <= E; i++){
  86.             players.erase(players.find_by_order(S));
  87.         }
  88.        
  89.         players.insert(pii(k.first, r.second));
  90.     }
  91.    
  92.     for (int i = 0; i < games.size(); i++){
  93.         int a = games[i].first; int b = games[i].second;
  94.         if (DS.query(a, b - 1) < R){
  95.             won_games.push_back(pii(a, b));
  96.         }
  97.     }
  98.    
  99.     for (int i = 0; i < won_games.size(); i++){
  100.         int a = won_games[i].first; int b = won_games[i].second;
  101.         diff[a]++;
  102.         diff[b + 1]--;
  103.     }
  104.     int res = 0;
  105.     int bes = 0;
  106.     int x = 0;
  107.     for (int i = 0; i < N; i++){
  108.         x += diff[i];
  109.         if (x > res){
  110.             res = x; bes = i;
  111.         }
  112.     }
  113.     cout << bes << endl;
  114.    
  115.    
  116.    
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement