답안 #1017659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017659 2024-07-09T09:23:26 Z cadmiumsky 송신탑 (IOI22_towers) C++17
11 / 100
4000 ms 8400 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;
   
   if([&]() {
      for(int i = L; i <= R; i++) 
         if(timeout[i] != 0) return 0;
      return 1;
   }()) {
      int mx = 0;
      for(int i = L; i <= R; i++) mx = max(mx, v[i]);
      return mx - max(v[L], v[R]) >= D? 2 : 1;
   }
   
   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(timeout[i] != 0 && 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(timeout[i] != 0 && 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 Correct 1337 ms 3416 KB Output is correct
2 Execution timed out 4051 ms 4184 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 1 ms 2680 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 2 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 2468 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 2 ms 2392 KB Output is correct
21 Correct 2 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 2 ms 2392 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 2 ms 2648 KB Output is correct
29 Correct 2 ms 2500 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 2 ms 2492 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 2680 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 2 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 2468 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 2 ms 2392 KB Output is correct
21 Correct 2 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 2 ms 2392 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 2 ms 2648 KB Output is correct
29 Correct 2 ms 2500 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 2 ms 2492 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 41 ms 6368 KB Output is correct
37 Incorrect 76 ms 8392 KB 1st lines differ - on the 1st token, expected: '2946', found: '2945'
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2162 ms 8144 KB 1st lines differ - on the 1st token, expected: '11903', found: '11902'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 689 ms 3928 KB Output is correct
2 Execution timed out 4003 ms 8400 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 1 ms 2680 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 2 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 2468 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 2 ms 2392 KB Output is correct
21 Correct 2 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 2 ms 2392 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 2 ms 2648 KB Output is correct
29 Correct 2 ms 2500 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 2 ms 2492 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 41 ms 6368 KB Output is correct
37 Incorrect 76 ms 8392 KB 1st lines differ - on the 1st token, expected: '2946', found: '2945'
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1337 ms 3416 KB Output is correct
2 Execution timed out 4051 ms 4184 KB Time limit exceeded
3 Halted 0 ms 0 KB -