답안 #626871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626871 2022-08-11T22:13:20 Z Monchito 송신탑 (IOI22_towers) C++17
27 / 100
4000 ms 5028 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

const int INF = 1e9 + 7;
const int MAXN = 1e5;

struct Node{
  int val;
  Node(){val = -INF;}
  void init(int _val){val = _val;}
};
Node merge(Node l, Node r){
  Node ret; ret.init(max(l.val, r.val));
  return ret;
}

bool subtask1 = true;
int n, k=0;
vector<int> h;

Node st[MAXN * 2];
void build(){
  for(int i=n-1; i>0; i--) st[i] = merge(st[i<<1],st[i<<1|1]);
}
void update(int p, Node val){
  for(st[p+=n] = val; p>>=1;) st[p] = merge(st[p<<1],st[p<<1|1]); 
}
Node query(int l, int r){
  Node resl, resr;
  for(l+=n, r+=n; l<r; l>>=1, r>>=1){
    if(l&1) resl=merge(resl,st[l++]);
    if(r&1) resr=merge(st[--r],resr);
  }
  return merge(resl, resr);
}

void init(int N, vector<int> H) {
  n = N;
  h = H;

  for(int i=1; i<n; i++){
    if(h[i] < h[i-1]) break;
    k = i;
  }
  for(int i=0; i<k; i++) subtask1 &= h[i] < h[k];
  for(int i=k+1; i<n; i++) subtask1 &= h[i] < h[k];
  for(int i=1; i<k; i++) subtask1 &= h[i-1] < h[i];
  for(int i=k+1; i<n; i++) subtask1 &= h[i] < h[i-1];

  for(int i=0; i<n; i++) st[i+n].init(h[i]);
  build();
}

int max_towers(int L, int R, int D) {
  if(subtask1){
    if(R < k || L > k || R - L + 1 < 3 || L == k || R == k) return 1;
    return (h[L] <= h[k] - D && h[R] <= h[k] - D) ? 2 : 1; 
  } 
  if (R - L + 1 < 3) return 1;

  vector<pair<int,int>> q;
  for(int i = L; i <= R; i++) q.pb(mp(h[i], i));
  sort(all(q));
  
  set<int> used;
  used.insert(q[0].snd);

  for(int i = 1; i < sz(q); i++){
    bool can=true;
    auto it = used.lower_bound(q[i].snd);
    if(it == used.end()) it--;

    int l = *it, r=q[i].snd;
    if(l>r) swap(l,r);
    if(r-l+1<3) can=false;
    else{
        int hk = query(l+1, r).val;
        if(!(h[l] <= hk - D && h[r] <= hk - D))
          can=false;
    }
    if(it != used.begin()){
      it--;
      l = *it, r=q[i].snd;
      if(l>r) swap(l,r);
      if(r-l+1<3) can=false;
      else{
        int hk = query(l+1, r).val;
        if(!(h[l] <= hk - D && h[r] <= hk - D))
          can=false;
      }
    }
    if(can) used.insert(q[i].snd);
  }
  return sz(used);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 428 ms 1744 KB Output is correct
2 Correct 819 ms 2256 KB Output is correct
3 Correct 652 ms 2220 KB Output is correct
4 Correct 749 ms 2232 KB Output is correct
5 Correct 814 ms 2240 KB Output is correct
6 Correct 810 ms 2244 KB Output is correct
7 Correct 875 ms 2256 KB Output is correct
8 Correct 1 ms 976 KB Output is correct
9 Correct 1 ms 1104 KB Output is correct
10 Correct 1 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 1 ms 1104 KB Output is correct
4 Correct 1 ms 1104 KB Output is correct
5 Correct 1 ms 1104 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 1 ms 976 KB Output is correct
10 Correct 1 ms 1104 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 1 ms 976 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 1 ms 1104 KB Output is correct
15 Correct 1 ms 1104 KB Output is correct
16 Correct 1 ms 1104 KB Output is correct
17 Correct 1 ms 1104 KB Output is correct
18 Correct 1 ms 1104 KB Output is correct
19 Correct 1 ms 1104 KB Output is correct
20 Correct 2 ms 1104 KB Output is correct
21 Correct 1 ms 1104 KB Output is correct
22 Correct 1 ms 1104 KB Output is correct
23 Correct 1 ms 976 KB Output is correct
24 Correct 1 ms 1104 KB Output is correct
25 Correct 1 ms 976 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1104 KB Output is correct
28 Correct 1 ms 1104 KB Output is correct
29 Correct 1 ms 1104 KB Output is correct
30 Correct 1 ms 1104 KB Output is correct
31 Correct 1 ms 1104 KB Output is correct
32 Correct 1 ms 976 KB Output is correct
33 Correct 1 ms 1104 KB Output is correct
34 Correct 1 ms 1104 KB Output is correct
35 Correct 1 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 1 ms 1104 KB Output is correct
4 Correct 1 ms 1104 KB Output is correct
5 Correct 1 ms 1104 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 1 ms 976 KB Output is correct
10 Correct 1 ms 1104 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 1 ms 976 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 1 ms 1104 KB Output is correct
15 Correct 1 ms 1104 KB Output is correct
16 Correct 1 ms 1104 KB Output is correct
17 Correct 1 ms 1104 KB Output is correct
18 Correct 1 ms 1104 KB Output is correct
19 Correct 1 ms 1104 KB Output is correct
20 Correct 2 ms 1104 KB Output is correct
21 Correct 1 ms 1104 KB Output is correct
22 Correct 1 ms 1104 KB Output is correct
23 Correct 1 ms 976 KB Output is correct
24 Correct 1 ms 1104 KB Output is correct
25 Correct 1 ms 976 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1104 KB Output is correct
28 Correct 1 ms 1104 KB Output is correct
29 Correct 1 ms 1104 KB Output is correct
30 Correct 1 ms 1104 KB Output is correct
31 Correct 1 ms 1104 KB Output is correct
32 Correct 1 ms 976 KB Output is correct
33 Correct 1 ms 1104 KB Output is correct
34 Correct 1 ms 1104 KB Output is correct
35 Correct 1 ms 1104 KB Output is correct
36 Correct 13 ms 1964 KB Output is correct
37 Correct 21 ms 2596 KB Output is correct
38 Correct 14 ms 2232 KB Output is correct
39 Correct 19 ms 2360 KB Output is correct
40 Correct 15 ms 2244 KB Output is correct
41 Correct 39 ms 3424 KB Output is correct
42 Correct 21 ms 2228 KB Output is correct
43 Correct 20 ms 2248 KB Output is correct
44 Correct 10 ms 2224 KB Output is correct
45 Correct 13 ms 2248 KB Output is correct
46 Correct 12 ms 2244 KB Output is correct
47 Correct 21 ms 2604 KB Output is correct
48 Correct 16 ms 2472 KB Output is correct
49 Correct 13 ms 2228 KB Output is correct
50 Correct 11 ms 2184 KB Output is correct
51 Correct 15 ms 2616 KB Output is correct
52 Correct 52 ms 4220 KB Output is correct
53 Correct 51 ms 4972 KB Output is correct
54 Correct 62 ms 4900 KB Output is correct
55 Correct 13 ms 2248 KB Output is correct
56 Correct 25 ms 3392 KB Output is correct
57 Correct 39 ms 3288 KB Output is correct
58 Correct 44 ms 3436 KB Output is correct
59 Correct 43 ms 3748 KB Output is correct
60 Correct 63 ms 5028 KB Output is correct
61 Correct 49 ms 4540 KB Output is correct
62 Correct 44 ms 4024 KB Output is correct
63 Correct 46 ms 4572 KB Output is correct
64 Correct 12 ms 2220 KB Output is correct
65 Correct 11 ms 2232 KB Output is correct
66 Correct 29 ms 3372 KB Output is correct
67 Correct 22 ms 3376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4005 ms 4556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4030 ms 2120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 1 ms 1104 KB Output is correct
4 Correct 1 ms 1104 KB Output is correct
5 Correct 1 ms 1104 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 1 ms 976 KB Output is correct
10 Correct 1 ms 1104 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 1 ms 976 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 1 ms 1104 KB Output is correct
15 Correct 1 ms 1104 KB Output is correct
16 Correct 1 ms 1104 KB Output is correct
17 Correct 1 ms 1104 KB Output is correct
18 Correct 1 ms 1104 KB Output is correct
19 Correct 1 ms 1104 KB Output is correct
20 Correct 2 ms 1104 KB Output is correct
21 Correct 1 ms 1104 KB Output is correct
22 Correct 1 ms 1104 KB Output is correct
23 Correct 1 ms 976 KB Output is correct
24 Correct 1 ms 1104 KB Output is correct
25 Correct 1 ms 976 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1104 KB Output is correct
28 Correct 1 ms 1104 KB Output is correct
29 Correct 1 ms 1104 KB Output is correct
30 Correct 1 ms 1104 KB Output is correct
31 Correct 1 ms 1104 KB Output is correct
32 Correct 1 ms 976 KB Output is correct
33 Correct 1 ms 1104 KB Output is correct
34 Correct 1 ms 1104 KB Output is correct
35 Correct 1 ms 1104 KB Output is correct
36 Correct 13 ms 1964 KB Output is correct
37 Correct 21 ms 2596 KB Output is correct
38 Correct 14 ms 2232 KB Output is correct
39 Correct 19 ms 2360 KB Output is correct
40 Correct 15 ms 2244 KB Output is correct
41 Correct 39 ms 3424 KB Output is correct
42 Correct 21 ms 2228 KB Output is correct
43 Correct 20 ms 2248 KB Output is correct
44 Correct 10 ms 2224 KB Output is correct
45 Correct 13 ms 2248 KB Output is correct
46 Correct 12 ms 2244 KB Output is correct
47 Correct 21 ms 2604 KB Output is correct
48 Correct 16 ms 2472 KB Output is correct
49 Correct 13 ms 2228 KB Output is correct
50 Correct 11 ms 2184 KB Output is correct
51 Correct 15 ms 2616 KB Output is correct
52 Correct 52 ms 4220 KB Output is correct
53 Correct 51 ms 4972 KB Output is correct
54 Correct 62 ms 4900 KB Output is correct
55 Correct 13 ms 2248 KB Output is correct
56 Correct 25 ms 3392 KB Output is correct
57 Correct 39 ms 3288 KB Output is correct
58 Correct 44 ms 3436 KB Output is correct
59 Correct 43 ms 3748 KB Output is correct
60 Correct 63 ms 5028 KB Output is correct
61 Correct 49 ms 4540 KB Output is correct
62 Correct 44 ms 4024 KB Output is correct
63 Correct 46 ms 4572 KB Output is correct
64 Correct 12 ms 2220 KB Output is correct
65 Correct 11 ms 2232 KB Output is correct
66 Correct 29 ms 3372 KB Output is correct
67 Correct 22 ms 3376 KB Output is correct
68 Execution timed out 4005 ms 4556 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 428 ms 1744 KB Output is correct
2 Correct 819 ms 2256 KB Output is correct
3 Correct 652 ms 2220 KB Output is correct
4 Correct 749 ms 2232 KB Output is correct
5 Correct 814 ms 2240 KB Output is correct
6 Correct 810 ms 2244 KB Output is correct
7 Correct 875 ms 2256 KB Output is correct
8 Correct 1 ms 976 KB Output is correct
9 Correct 1 ms 1104 KB Output is correct
10 Correct 1 ms 976 KB Output is correct
11 Correct 1 ms 976 KB Output is correct
12 Correct 1 ms 1104 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 1 ms 1104 KB Output is correct
15 Correct 1 ms 1104 KB Output is correct
16 Correct 1 ms 976 KB Output is correct
17 Correct 1 ms 1104 KB Output is correct
18 Correct 2 ms 1104 KB Output is correct
19 Correct 1 ms 976 KB Output is correct
20 Correct 1 ms 1104 KB Output is correct
21 Correct 1 ms 1104 KB Output is correct
22 Correct 1 ms 976 KB Output is correct
23 Correct 1 ms 1104 KB Output is correct
24 Correct 1 ms 1104 KB Output is correct
25 Correct 1 ms 1104 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1104 KB Output is correct
28 Correct 1 ms 1104 KB Output is correct
29 Correct 1 ms 1104 KB Output is correct
30 Correct 2 ms 1104 KB Output is correct
31 Correct 1 ms 1104 KB Output is correct
32 Correct 1 ms 1104 KB Output is correct
33 Correct 1 ms 976 KB Output is correct
34 Correct 1 ms 1104 KB Output is correct
35 Correct 1 ms 976 KB Output is correct
36 Correct 1 ms 1104 KB Output is correct
37 Correct 1 ms 1104 KB Output is correct
38 Correct 1 ms 1104 KB Output is correct
39 Correct 1 ms 1104 KB Output is correct
40 Correct 1 ms 1104 KB Output is correct
41 Correct 1 ms 1104 KB Output is correct
42 Correct 1 ms 976 KB Output is correct
43 Correct 1 ms 1104 KB Output is correct
44 Correct 1 ms 1104 KB Output is correct
45 Correct 1 ms 1104 KB Output is correct
46 Correct 13 ms 1964 KB Output is correct
47 Correct 21 ms 2596 KB Output is correct
48 Correct 14 ms 2232 KB Output is correct
49 Correct 19 ms 2360 KB Output is correct
50 Correct 15 ms 2244 KB Output is correct
51 Correct 39 ms 3424 KB Output is correct
52 Correct 21 ms 2228 KB Output is correct
53 Correct 20 ms 2248 KB Output is correct
54 Correct 10 ms 2224 KB Output is correct
55 Correct 13 ms 2248 KB Output is correct
56 Correct 12 ms 2244 KB Output is correct
57 Correct 21 ms 2604 KB Output is correct
58 Correct 16 ms 2472 KB Output is correct
59 Correct 13 ms 2228 KB Output is correct
60 Correct 11 ms 2184 KB Output is correct
61 Correct 15 ms 2616 KB Output is correct
62 Correct 52 ms 4220 KB Output is correct
63 Correct 51 ms 4972 KB Output is correct
64 Correct 62 ms 4900 KB Output is correct
65 Correct 13 ms 2248 KB Output is correct
66 Correct 25 ms 3392 KB Output is correct
67 Correct 39 ms 3288 KB Output is correct
68 Correct 44 ms 3436 KB Output is correct
69 Correct 43 ms 3748 KB Output is correct
70 Correct 63 ms 5028 KB Output is correct
71 Correct 49 ms 4540 KB Output is correct
72 Correct 44 ms 4024 KB Output is correct
73 Correct 46 ms 4572 KB Output is correct
74 Correct 12 ms 2220 KB Output is correct
75 Correct 11 ms 2232 KB Output is correct
76 Correct 29 ms 3372 KB Output is correct
77 Correct 22 ms 3376 KB Output is correct
78 Execution timed out 4005 ms 4556 KB Time limit exceeded
79 Halted 0 ms 0 KB -