QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#344745#4563. Radio Towershos_lyric0 17ms4304kbC++144.7kb2024-03-05 04:35:152024-03-05 04:35:15

Judging History

你现在查看的是最新测评结果

  • [2024-03-05 04:35:15]
  • 评测
  • 测评结果:0
  • 用时:17ms
  • 内存:4304kb
  • [2024-03-05 04:35:15]
  • 提交

answer

#include "towers.h"

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


struct Set {
  // max{ceil(log_64(n)), 1}
  int log64N, n;
  vector<unsigned long long> a[6];
  explicit Set(int n_ = 0) : n(n_) {
    assert(n >= 0);
    int m = n ? n : 1;
    for (int d = 0; ; ++d) {
      m = (m + 63) >> 6;
      a[d].assign(m, 0);
      if (m == 1) {
        log64N = d + 1;
        break;
      }
    }
  }
  bool empty() const {
    return !a[log64N - 1][0];
  }
  bool contains(int x) const {
    return (a[0][x >> 6] >> (x & 63)) & 1;
  }
  void insert(int x) {
    for (int d = 0; d < log64N; ++d) {
      const int q = x >> 6, r = x & 63;
      a[d][q] |= 1ULL << r;
      x = q;
    }
  }
  void erase(int x) {
    for (int d = 0; d < log64N; ++d) {
      const int q = x >> 6, r = x & 63;
      if ((a[d][q] &= ~(1ULL << r))) break;
      x = q;
    }
  }
  // max s.t. <= x (or -1)
  int prev(int x) const {
    if (x > n - 1) x = n - 1;
    for (int d = 0; d <= log64N; ++d) {
      if (x < 0) break;
      const int q = x >> 6, r = x & 63;
      const unsigned long long lower = a[d][q] << (63 - r);
      if (lower) {
        x -= __builtin_clzll(lower);
        for (int e = d; --e >= 0; ) x = x << 6 | (63 - __builtin_clzll(a[e][x]));
        return x;
      }
      x = q - 1;
    }
    return -1;
  }
  // min s.t. >= x (or n)
  int next(int x) const {
    if (x < 0) x = 0;
    for (int d = 0; d < log64N; ++d) {
      const int q = x >> 6, r = x & 63;
      if (static_cast<unsigned>(q) >= a[d].size()) break;
      const unsigned long long upper = a[d][q] >> r;
      if (upper) {
        x += __builtin_ctzll(upper);
        for (int e = d; --e >= 0; ) x = x << 6 | __builtin_ctzll(a[e][x]);
        return x;
      }
      x = q + 1;
    }
    return n;
  }
};

////////////////////////////////////////////////////////////////////////////////


constexpr int INF = 1001001001;

int N;
vector<pair<int, int>> anss;

void init(int N_, std::vector<int> H) {
  N = N_;
  vector<int> is;
  for (int i = 0, j, k; i < N - 1; i = k) {
    for (j = i; j < N - 1 && H[j] < H[j + 1]; ++j) {}
    for (k = j; k < N - 1 && H[k] > H[k + 1]; ++k) {}
    if (i < j && j < k) {
      if (is.size()) {
        assert(is.back() == i);
        is.pop_back();
      }
      is.push_back(i);
      is.push_back(j);
      is.push_back(k);
    }
  }
  int now = (int)is.size() / 2;
  Set on(N);
  using Entry = pair<int, pair<int, int>>;
  priority_queue<Entry, vector<Entry>, greater<Entry>> que;
  for (const int i : is) {
    on.insert(i);
  }
  for (int j = 0; j < 2 * now; ++j) {
    que.emplace(abs(H[is[j]] - H[is[j + 1]]), make_pair(is[j], is[j + 1]));
  }
  for (; que.size(); ) {
    const int d = que.top().first;
    const int i = que.top().second.first;
    const int j = que.top().second.second;
    que.pop();
    if (on.contains(i) && on.contains(j)) {
// cerr<<"d = "<<d<<", i = "<<i<<", j = "<<j<<"; on = ";for(int k=0;k<N;++k)if(on.contains(k))cerr<<make_pair(H[k],k)<<" ";cerr<<endl;
      anss.emplace_back(d, -now);
      now -= 2;
      on.erase(i);
      on.erase(j);
      const int l = on.prev(i);
      const int r = on.next(j);
      if (0 <= l && r < N) {
        que.emplace(abs(H[l] - H[r]), make_pair(l, r));
      }
    }
  }
  anss.emplace_back(INF, -1);
// cerr<<"anss = "<<anss<<endl;
}

int max_towers(int L, int R, int D) {
  ++R;
  assert(L == 0);
  assert(R == N);
  return -lower_bound(anss.begin(), anss.end(), make_pair(D, -INF))->second + 1;
}

詳細信息

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

59640
49885 57346 58504 87383 113182 129676 204090 205404 259925 276583 300332 324014 333675 359377 364049 408489 414852 428310 438038 440113 458193 554789 643468 666525 683112 690791 707313 720088 741028 748785 789826 796576 800966 832867 851750 861044 862283 900756 926925 939560 955678 965636 9740...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #8:

score: 0
Runtime Error

input:

425
753881706 405729786 890889563 29736246 598281970 208352067 357783003 663497023 178397034 4832890 562140755 510307001 354540290 538848551 436879256 86659033 42928516 24145404 749159097 118423198 506851985 204895765 719719998 726244368 991372008 681703480 799303017 657138050 88278945 417801236 260...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Runtime Error

Test #65:

score: 0
Runtime Error

input:

99308
491693640 24020487 317364185 726230755 737284540 951143270 709116045 641023337 360629062 964879440 47884022 532494780 803629825 635450854 688041998 573937055 113198481 191311841 929603572 636688 598629732 895342035 396521271 619919754 716589045 657789547 373121546 866402108 609316614 60046511 ...

output:


result:


Subtask #5:

score: 0
Wrong Answer

Test #86:

score: 0
Wrong Answer
time: 17ms
memory: 4304kb

input:

23881
605288257 422163932 155875880 339929874 76049859 196344969 958160745 767945284 469191956 997116006 387749577 15911341 920437918 367576975 800789357 351557615 283723284 369507452 841548133 643412903 309731505 256549694 370065644 699518122 559017597 347646657 469353381 575240521 501893001 454519...

output:

6390
6122
-7704
2056
2450
6662
-4448
5346
-3980
3838
1752
6950
1192
-2466
2716
4926
7316
6464
7584
-2484
4638
6108
6600
1494
-7076
-3946
3296
-4058
4450
1796
1928
1976
-1720
-6434
3632
-1994
7406
5930
-4124
3756
6398
1500
-5448
5104
-2102
-6216
5198
6034
6468
4148
2360
5154
-3318
-3864
670
3484
870
...

result:

wrong answer 3rd lines differ - expected: '7197', found: '6390'

Subtask #6:

score: 0
Runtime Error

Test #97:

score: 0
Runtime Error

input:

88768
238644804 620122421 789364401 899010695 885388612 437964772 845379533 657562749 773925456 625793781 916240972 291506550 379611161 905077982 629848170 530056471 520438258 806293637 326792996 785404568 74285074 565304193 846963319 63529729 804909008 212070492 69936548 656129389 408708069 3070450...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #1:

0%