Submission #1057102

# Submission time Handle Problem Language Result Execution time Memory
1057102 2024-08-13T14:09:06 Z mychecksedad Radio Towers (IOI22_towers) C++17
17 / 100
608 ms 13076 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 Fenwick{
  vector<int> t;
  int n;
  Fenwick(int n): n(n){
    t.resize(n+1);
  }
  void add(int v){
    while(v <= n){
      t[v]++;
      v += v&-v;
    }
  }
  int get(int v){
    int res = 0;
    while(v > 0){
      res += t[v];
      v -= v&-v;
    }
    return res;
  }
};


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, A2, A1, B1, B2, a;
Fenwick f(1000000);

  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());
  if(A.size()==1) return;
  if(A.back() > A[A.size() - 2]) A.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 + 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});
  }
  ans.pb({1, 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 'void op(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
towers.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int i = 2; i < a.size(); ++i){
      |                  ~~^~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:119: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]
  119 |   return max(pos == ans.size() ? 1 : ans[pos].ss, 1);
      |              ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 224 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4184 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4184 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 456 ms 10568 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 174 ms 5832 KB Output is correct
2 Correct 577 ms 10568 KB Output is correct
3 Correct 513 ms 10820 KB Output is correct
4 Correct 591 ms 12964 KB Output is correct
5 Correct 582 ms 12908 KB Output is correct
6 Correct 544 ms 12860 KB Output is correct
7 Correct 608 ms 12860 KB Output is correct
8 Correct 496 ms 5464 KB Output is correct
9 Correct 510 ms 5464 KB Output is correct
10 Correct 500 ms 5464 KB Output is correct
11 Correct 491 ms 5464 KB Output is correct
12 Correct 40 ms 10648 KB Output is correct
13 Correct 69 ms 12860 KB Output is correct
14 Correct 58 ms 13020 KB Output is correct
15 Correct 8 ms 5464 KB Output is correct
16 Correct 13 ms 5376 KB Output is correct
17 Correct 38 ms 10124 KB Output is correct
18 Correct 41 ms 10560 KB Output is correct
19 Correct 46 ms 10568 KB Output is correct
20 Correct 67 ms 12860 KB Output is correct
21 Correct 60 ms 12860 KB Output is correct
22 Correct 59 ms 12928 KB Output is correct
23 Correct 59 ms 13076 KB Output is correct
24 Correct 10 ms 5464 KB Output is correct
25 Correct 8 ms 5464 KB Output is correct
26 Correct 8 ms 5464 KB Output is correct
27 Correct 16 ms 5464 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 2 ms 4440 KB Output is correct
31 Correct 1 ms 4184 KB Output is correct
32 Correct 1 ms 4184 KB Output is correct
33 Correct 1 ms 4184 KB Output is correct
34 Correct 1 ms 4252 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 2 ms 4440 KB Output is correct
37 Correct 2 ms 4440 KB Output is correct
38 Correct 2 ms 4440 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4184 KB Output is correct
41 Correct 1 ms 4184 KB Output is correct
42 Correct 1 ms 4184 KB Output is correct
43 Correct 1 ms 4184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4184 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 224 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -