Submission #790814

# Submission time Handle Problem Language Result Execution time Memory
790814 2023-07-23T08:12:21 Z penguinman Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 2696 KB
#include "towers.h"

#include <bits/stdc++.h>

using std::vector;
using std::string;
using std::cin;
using std::cout;
using ll = int;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define ln "\n"
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define all(a) a.begin(), a.end()
#define mp std::make_pair
#define pb emplace_back
constexpr ll inf = (1<<30)+(1<<29)+(1<<28);

ll N;
vi H;
ll D;
vi right, left;

void init(int n, std::vector<int> h) {
  N = n;
  H.resize(N);
  right.resize(N);
  left.resize(N);
  rep(i,0,N) H[i] = h[i];
  D = -1;
}

int max_towers(int L, int R, int d) {
  if(D == -1){
    D = d;
    {
      std::deque<ll> ima, vma, imi, vmi;
      ima.pb(-3);
      vma.pb(-inf);
      imi.pb(-2);
      vmi.pb(inf);
      rep(i,0,N){
        ll large = lower_bound(all(vmi), H[i]+D)-vmi.begin();
        large = imi[large];
        ll small = lower_bound(all(vma),H[i])-vma.begin()-1;
        small = ima[small];
        if(small >= large) left[i] = small+1;
        else left[i] = -1;
        while(true){
          if(vma[vma.size()-1] > H[i]) vma.pop_back(), ima.pop_back();
          else break;
        }
        vma.pb(H[i]);
        ima.pb(i);
        while(true){
          if(vmi[0] < H[i]) vmi.pop_front(), imi.pop_front();
          else break;
        }
        vmi.emplace_front(H[i]);
        imi.emplace_front(i);
      }
    }
    {
      std::deque<ll> ima, vma, imi, vmi;
      ima.pb(N+3);
      vma.pb(-inf);
      imi.pb(N+2);
      vmi.pb(inf);
      per(i,N-1,0){
        ll large = lower_bound(all(vmi), H[i]+D)-vmi.begin();
        large = imi[large];
        ll small = lower_bound(all(vma),H[i])-vma.begin()-1;
        small = ima[small];
        if(small <= large) right[i] = small-1;
        else right[i] = N;
        while(true){
          if(vma[vma.size()-1] > H[i]) vma.pop_back(), ima.pop_back();
          else break;
        }
        vma.pb(H[i]);
        ima.pb(i);
        while(true){
          if(vmi[0] < H[i]) vmi.pop_front(), imi.pop_front();
          else break;
        }
        vmi.emplace_front(H[i]);
        imi.emplace_front(i);
      }
    }
  }
  ll ans = 0;
  REP(idx,L,R){
    if(left[idx] <= L && R <= right[idx]) ans++;
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1082 ms 1660 KB 31st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 220 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 276 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 220 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 276 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 19 ms 1700 KB Output is correct
37 Correct 27 ms 2212 KB Output is correct
38 Correct 23 ms 2200 KB Output is correct
39 Correct 32 ms 2256 KB Output is correct
40 Correct 28 ms 2224 KB Output is correct
41 Correct 24 ms 2188 KB Output is correct
42 Correct 20 ms 2208 KB Output is correct
43 Correct 38 ms 2652 KB Output is correct
44 Correct 34 ms 2584 KB Output is correct
45 Correct 32 ms 2384 KB Output is correct
46 Correct 28 ms 2388 KB Output is correct
47 Correct 31 ms 2248 KB Output is correct
48 Correct 22 ms 2224 KB Output is correct
49 Correct 20 ms 2228 KB Output is correct
50 Correct 31 ms 2696 KB Output is correct
51 Correct 27 ms 2672 KB Output is correct
52 Correct 23 ms 2200 KB Output is correct
53 Correct 21 ms 2212 KB Output is correct
54 Correct 27 ms 2208 KB Output is correct
55 Correct 25 ms 2588 KB Output is correct
56 Correct 24 ms 2616 KB Output is correct
57 Correct 22 ms 2188 KB Output is correct
58 Correct 25 ms 2244 KB Output is correct
59 Correct 28 ms 2228 KB Output is correct
60 Correct 20 ms 2196 KB Output is correct
61 Correct 32 ms 2204 KB Output is correct
62 Correct 22 ms 2208 KB Output is correct
63 Correct 26 ms 2228 KB Output is correct
64 Correct 30 ms 2612 KB Output is correct
65 Correct 28 ms 2596 KB Output is correct
66 Correct 34 ms 2380 KB Output is correct
67 Correct 32 ms 2620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4029 ms 2204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3139 ms 756 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 220 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 276 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 19 ms 1700 KB Output is correct
37 Correct 27 ms 2212 KB Output is correct
38 Correct 23 ms 2200 KB Output is correct
39 Correct 32 ms 2256 KB Output is correct
40 Correct 28 ms 2224 KB Output is correct
41 Correct 24 ms 2188 KB Output is correct
42 Correct 20 ms 2208 KB Output is correct
43 Correct 38 ms 2652 KB Output is correct
44 Correct 34 ms 2584 KB Output is correct
45 Correct 32 ms 2384 KB Output is correct
46 Correct 28 ms 2388 KB Output is correct
47 Correct 31 ms 2248 KB Output is correct
48 Correct 22 ms 2224 KB Output is correct
49 Correct 20 ms 2228 KB Output is correct
50 Correct 31 ms 2696 KB Output is correct
51 Correct 27 ms 2672 KB Output is correct
52 Correct 23 ms 2200 KB Output is correct
53 Correct 21 ms 2212 KB Output is correct
54 Correct 27 ms 2208 KB Output is correct
55 Correct 25 ms 2588 KB Output is correct
56 Correct 24 ms 2616 KB Output is correct
57 Correct 22 ms 2188 KB Output is correct
58 Correct 25 ms 2244 KB Output is correct
59 Correct 28 ms 2228 KB Output is correct
60 Correct 20 ms 2196 KB Output is correct
61 Correct 32 ms 2204 KB Output is correct
62 Correct 22 ms 2208 KB Output is correct
63 Correct 26 ms 2228 KB Output is correct
64 Correct 30 ms 2612 KB Output is correct
65 Correct 28 ms 2596 KB Output is correct
66 Correct 34 ms 2380 KB Output is correct
67 Correct 32 ms 2620 KB Output is correct
68 Execution timed out 4029 ms 2204 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1082 ms 1660 KB 31st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -