QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#365322 | #7939. High Towers | EMBailey# | WA | 50ms | 23908kb | C++14 | 1.5kb | 2024-03-25 02:58:58 | 2024-03-25 02:58:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define sz(C) int(C.size())
struct RMQ
{
vector<int> A;
vector<vector<int>> jmp;
RMQ(){
}
RMQ(const vector<int> &V) : jmp(1, V), A(V)
{
for(int i = 0; i < A.size(); i++){
jmp[0][i] = i;
}
for (int pw = 1, k = 1; pw * 2 <= sz(V); pw *= 2, ++k)
{
jmp.emplace_back(sz(V) - pw * 2 + 1);
rep(j, 0, sz(jmp[k])) {
int l = jmp[k-1][j];
int r = jmp[k-1][j+pw];
if(A[l] > A[r]){
jmp[k][j] = l;
}
else{
jmp[k][j] = r;
}
}
}
}
int query(int a, int b)
{
if (a >= b)
return 0;
int dep = 31 - __builtin_clz(b - a);
//cout << dep << " " << a << " " << b << " " << jmp.size() << endl;
int l = jmp[dep][a];
int r = jmp[dep][b - (1 << dep)];
if(A[l] > A[r]){
return l;
}
return r;
}
};
RMQ Q;
vector<int> A;
vector<int> res;
void solve(int l, int r){
if(r < l) return;
int N = r-l+1;
int ind = Q.query(l, r+1);
//cout << ind << endl;
assert(l <= ind && r >= ind);
res[ind] = N;
solve(l, ind-1);
solve(ind+1, r);
}
int main(int argc, char const *argv[])
{
if (argc > 1)
{
ignore = freopen(argv[1], "r", stdin);
ignore = freopen(argv[2], "w", stdout);
}
int N;
cin >> N;
A = vector<int>(N, 0);
res = vector<int>(N, 0);
for(int i = 0; i < N; i++){
cin >> A[i];
}
Q = RMQ(A);
//cout << "done\n";
solve(0, N-1);
for(int i = 0; i < N; i++){
cout << res[i] << " ";
}
cout << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3748kb
input:
6 3 3 4 2 5 1
output:
1 2 4 1 6 1
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
4 3 3 3 3
output:
1 2 3 4
result:
ok
Test #3:
score: -100
Wrong Answer
time: 50ms
memory: 23908kb
input:
264668 5 5 5 5 9 5 5 5 7 3 5 3 11 9 9 9 8 9 8 9 12 4 4 9 5 5 6 4 12 4 7 5 6 5 18 12 6 12 11 11 11 11 11 11 12 19 5 5 8 6 6 6 26 7 7 7 8 6 7 6 6 12 10 6 9 8 8 8 10 4 22 4 4 6 3 6 4 4 8 5 5 5 7 3 8 6 6 6 6 8 3 5 3 6 4 4 8 5 5 5 10 6 6 6 6 17 4 12 5 11 6 10 7 9 8 8 16 5 5 5 8 4 4 12 8 7 7 8 6 9 4 14 5 ...
output:
1 2 3 4 12 1 2 3 7 1 3 1 20 1 2 4 1 6 1 7 28 1 2 7 1 2 4 1 34 1 5 1 3 1 45 2 1 9 1 2 3 4 5 6 10 52 1 2 6 1 2 3 180 1 2 3 8 1 4 1 2 17 6 1 5 1 2 3 8 1 112 1 2 4 1 7 1 2 13 1 2 3 5 1 18 1 2 3 4 25 1 3 1 6 1 2 29 1 2 3 34 1 2 3 4 75 1 10 1 8 1 6 1 4 1 2 30 1 2 3 6 1 2 14 3 1 2 5 1 7 1 19 1 2 4 1 40 1 2...
result:
wrong answer