답안 #1057451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057451 2024-08-13T20:08:50 Z mychecksedad 송신탑 (IOI22_towers) C++17
17 / 100
656 ms 9196 KB
#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long int
#define en cout << '\n'
#define pii pair<int,int>
#define vi vector<int> 
#define ff first
#define ss second

struct Node{
  Node *L, *R;
  int sum;
  Node(){
    L=R=nullptr;
    sum=0;
  }
  Node(Node*l, Node*r): L(l), R(r){
    sum = 0;
    if(l != nullptr) sum += l->sum;
    if(r != nullptr) sum += r->sum;
  }
  Node(int s): sum(s){
    L=R=nullptr;
  }
};
vector<bool> is_peak(300005);

Node *build(int l, int r){
  if(l == r){
    return new Node(is_peak[l]);
  }
  int m = l+r>>1;
  return new Node(build(l, m), build(m+1, r));
}

Node *upd(Node *v, int l, int r, int p, int val){
  if(l == r){
    return new Node(val);
  }
  int m = l+r>>1;
  if(p <= m) return new Node(upd(v->L, l, m, p, val), v->R);
  return new Node(v->L, upd(v->R, m+1, r, p, val));
}

int get(Node *vl, Node *vr, int l, int r, int ql, int qr){
  if(ql > r || l > qr) return 0;
  if(ql <= l && r <= qr) return vr->sum - vl->sum;
  int m = l+r>>1;
  return get(vl->L, vr->L, l, m, ql, qr) + get(vl->R, vr->R, m+1, r, ql, qr);
}

void op(vector<int> &a, vector<int> &A, vector<int> &B){
  if(a.size() <= 1){
    A = a;
    B.pb(0);
    return;
  }
  A.pb(a[0]);
  A.pb(a[1]);
  B.pb(0);
  B.pb(1);
  for(int i = 2; i < a.size(); ++i){
    if(a[i] > A.back() && A.back() > A[int(A.size()) - 2]){
      A.pop_back();
      B.pop_back();
      A.pb(a[i]);
      B.pb(i);
    }else if(a[i] < A.back() && A.back() < A[int(A.size()) - 2]){
      A.pop_back();
      B.pop_back();
      A.pb(a[i]);
      B.pb(i);
    }else{
      A.pb(a[i]);
      B.pb(i);
    }
  }
  
}
int n;
vector<int> A, B, a;
vector<pair<int, int>> ans;
void init(int nn, std::vector<int> aa) { n=nn;a=aa;
  if(n == 1) return;
  op(a, A, B);


  if(A[0] > A[1]) A.erase(A.begin()), B.erase(B.begin());
  if(A.size()==1) return;
  if(A.back() > A[A.size() - 2]) A.pop_back(), B.pop_back();
  if(A.size()==1) return;

  set<pair<int,int>> S;
  priority_queue<array<int, 3>> Q;

  int m = A.size();
  for(int i = 0; i < m; ++i){
    S.insert({i, A[i]});
    if(i%2) is_peak[B[i]] = 1;
    if(i + 1 < m && A[i + 1] > A[i]) Q.push({-(A[i + 1] - A[i]), i, i + 1});
    if(i > 0 && A[i - 1] > A[i]) Q.push({-(A[i - 1] - A[i]), i, i - 1});
  }
  vector<pair<int, Node*>> roots;
  // roots.pb({1, });

  ans.pb({0, A.size() / 2 + 1});
  vector<bool> rem(A.size());
  while(!Q.empty()){
    auto V = Q.top();
    int v = V[1], u = V[2];
    int val = V[0];
    Q.pop();
    if(rem[u] || rem[v]) continue;
    S.erase({v, A[v]});
    S.erase({u, A[u]});
    rem[u] = rem[v] = 1;
    int mx = max(u, v);
    auto it = S.lower_bound(pair<int,int>{mx, -1});
    if(it != S.begin() && it != S.end()){
      auto it2 = prev(it);
      auto x = *it;
      auto y = *it2;
      Q.push({-abs(x.ss - y.ss), x.ff, y.ff});
    }
    // assert(S.size()%2);
    if(ans.back().ff == -val){
      ans.back().ss = S.size() / 2 + 1;
    }else ans.pb({-val, S.size() / 2 + 1});
  }

}

int max_towers(int L, int R, int D) { ++L, ++R;
  if(n == 1 || L == R || A.size() == 1) return 1;
  int pos = upper_bound(all(ans), pii{D, -1}) - ans.begin() - 1;
  // if(D==1) return ans[0].ss;
  return max(pos == ans.size() ? 1 : ans[pos].ss, 1);
}

Compilation message

towers.cpp: In function 'Node* build(int, int)':
towers.cpp:35:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   int m = l+r>>1;
      |           ~^~
towers.cpp: In function 'Node* upd(Node*, int, int, int, int)':
towers.cpp:43:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |   int m = l+r>>1;
      |           ~^~
towers.cpp: In function 'int get(Node*, Node*, int, int, int, int)':
towers.cpp:51:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |   int m = l+r>>1;
      |           ~^~
towers.cpp: In function 'void op(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
towers.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i = 2; i < a.size(); ++i){
      |                  ~~^~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:140:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |   return max(pos == ans.size() ? 1 : ans[pos].ss, 1);
      |              ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 236 ms 1112 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 401 ms 6688 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 1876 KB Output is correct
2 Correct 524 ms 6640 KB Output is correct
3 Correct 600 ms 6652 KB Output is correct
4 Correct 604 ms 9196 KB Output is correct
5 Correct 656 ms 9196 KB Output is correct
6 Correct 578 ms 9112 KB Output is correct
7 Correct 593 ms 9196 KB Output is correct
8 Correct 537 ms 1624 KB Output is correct
9 Correct 532 ms 1624 KB Output is correct
10 Correct 513 ms 1624 KB Output is correct
11 Correct 491 ms 1624 KB Output is correct
12 Correct 44 ms 6640 KB Output is correct
13 Correct 57 ms 9196 KB Output is correct
14 Correct 57 ms 9184 KB Output is correct
15 Correct 7 ms 1624 KB Output is correct
16 Correct 8 ms 1624 KB Output is correct
17 Correct 37 ms 6196 KB Output is correct
18 Correct 43 ms 6648 KB Output is correct
19 Correct 53 ms 6816 KB Output is correct
20 Correct 68 ms 8992 KB Output is correct
21 Correct 59 ms 9196 KB Output is correct
22 Correct 57 ms 9196 KB Output is correct
23 Correct 62 ms 9196 KB Output is correct
24 Correct 9 ms 1620 KB Output is correct
25 Correct 12 ms 1624 KB Output is correct
26 Correct 7 ms 1624 KB Output is correct
27 Correct 8 ms 1636 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 624 KB Output is correct
37 Correct 2 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 236 ms 1112 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -