QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344746 | #4563. Radio Towers | hos_lyric | 0 | 8ms | 4200kb | C++14 | 4.7kb | 2024-03-05 04:37:20 | 2024-03-05 04:37:20 |
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;
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;
}
Details
Tip: Click on the bar to expand more detailed information
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: 8ms
memory: 4200kb
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:
7197 7063 150 5030 5227 7333 1778 6675 2012 5921 4878 7477 4598 2769 5360 6465 7660 7234 7794 2760 6321 7056 7302 4749 464 2029 5650 1973 6227 4900 4966 4990 3142 785 5818 3005 7705 6967 1940 5880 7201 4752 1278 6554 2951 894 6601 7019 7236 6076 5182 6579 2343 2070 4337 5744 4437 2262 6686 1739 7756...
result:
wrong answer 2259th lines differ - expected: '1', found: '2'
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%