답안 #1017634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017634 2024-07-09T09:15:34 Z cadmiumsky 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 8208 KB
#include "towers.h"

#include <vector>
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 1e5 + 5;
int v[nmax];

namespace DSU {
   int dsu[nmax], nxt[nmax];
   int mxR[nmax];

   void init(int l, int r) {
      for(int i = l; i <= r; i++) dsu[i] = i, nxt[i] = i + 1;
      return;
   }
   int f(int x) { return x == dsu[x]? x : dsu[x] = f(dsu[x]); }
   void unite(int x, int y) {
      x = f(x);
      y = f(y);
      if(x == y) return;
      if(x > y) swap(x, y);
      dsu[y] = x;
      mxR[x] = max(mxR[x], mxR[y]);
      nxt[x] = nxt[y];
      return;
   }
   int coef(int i, const vector<int>& p) {
      i = f(i);
      return mxR[i] - max(v[p[i]], v[p[nxt[i]]]);
   }
}

int timeout[nmax];

void initglobals(signed L, signed R) {
   
   ++L;
   ++R;
   
   vector<int> p;
   for(int i = L; i <= R; i++) {
      if((i == L  || v[i] < v[i - 1]) && (i == R || v[i] < v[i + 1])) p.emplace_back(i), timeout[i] = 1e9 + 5;
      else timeout[i] = 0;
   }
   
   DSU::init(0, sz(p));
   
   set<pii> heap;
   
   set<int> indemnizatii;
   for(int i = 0; i < sz(p) - 1; i++) {
      indemnizatii.emplace(i);
      indemnizatii.emplace(i + 1);
      int mx = v[p[i] + 1];
      for(int j = p[i] + 2; j < p[i + 1]; j++)
         mx = max(mx, v[j]);
      DSU::mxR[i] = mx;
      heap.emplace(mx - max(v[p[i]], v[p[i + 1]]), i);
   }
   
   auto get = [&](int p_) { return pii{DSU::coef(p_, p), p_}; };
      
   while(!heap.empty()) {
      auto [C, i] = *heap.begin();
      heap.erase(heap.begin());
      
      i = DSU::f(i);
      int urm = DSU::nxt[i];
      if(i != *indemnizatii.begin()) {
         int ant = DSU::f(i - 1);
         heap.erase(heap.find(get(ant)));
      }
      if(urm != *indemnizatii.rbegin()) 
         heap.erase(heap.find(get(urm)));
      
      if(v[p[i]] < v[p[urm]]) {
         timeout[p[urm]] = C;
         DSU::unite(i, urm);
         indemnizatii.erase(urm);
         if(i != *indemnizatii.begin()) {
            int ant = DSU::f(i - 1);
            heap.insert(get(ant));
         }
         if(i != *indemnizatii.rbegin())
            heap.insert(get(i));
         
      }
      else {
         timeout[p[i]] = C;
         if(i != *indemnizatii.begin()) {
            int ant = DSU::f(i - 1);
            DSU::unite(ant, i);
            heap.insert(get(ant));
         }
         if(urm != *indemnizatii.rbegin())
            heap.insert(get(urm));
         indemnizatii.erase(i);
      }  
   }
}


void init(signed N, std::vector<signed> H) {
   for(int i = 0; i < N; i++) v[i + 1] = H[i]; 
   initglobals(0, N - 1);
}


signed max_towers(signed L, signed R, signed D) {
   ++L, ++R;
   int l = L, r = R;
   while (l <= r && timeout[l] < D) l++;
   if(l > r) return 1;
   
   int rez = 0;
   if(L < l) {
      int mn = L;
      for(int i = L + 1; i < l; i++) if(v[mn] > v[i]) mn = i;
      int mx = 0;
      for(int i = mn + 1; i < l; i++) mx = max(v[i], mx);
      if(mx - max(v[l], v[mn]) >= D) rez++;
   }
   
   while(timeout[r] < D) r--;
   
   if(r < R) {
      int mn = R;
      for(int i = r + 1; i < R; i++) if(v[mn] > v[i]) mn = i;
      int mx = 0;
      for(int i = r + 1; i < r; i++) mx = max(v[i], mx);
      if(mx - max(v[r], v[mn]) >= D) rez++;
   }
   
   for(int i = l; i <= r; i++)
      if(timeout[i] >= D) rez++;
   return rez;
}
#undef int
# 결과 실행 시간 메모리 Grader output
1 Incorrect 707 ms 3416 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 2 ms 2648 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Incorrect 0 ms 2392 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 2 ms 2648 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Incorrect 0 ms 2392 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2414 ms 8120 KB 1st lines differ - on the 1st token, expected: '11903', found: '11902'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 708 ms 3928 KB Output is correct
2 Execution timed out 4080 ms 8208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 2 ms 2648 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Incorrect 0 ms 2392 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 707 ms 3416 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -