QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419970 | #7939. High Towers | gabrielwu | WA | 45ms | 18908kb | C++20 | 3.3kb | 2024-05-24 13:26:25 | 2024-05-24 13:26:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<(n); i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
template<typename A, typename B> ostream& operator<<(ostream & cout, pair<A,B> const &p) {
return cout << "("<< p.f << ", "<< p.s << ")";
}
template<typename A> ostream& operator<<(ostream &cout, vector<A> const & v) {
cout << "[";
forn(i, v.size()) {
if(i) cout << ", ";
cout << v[i];
}
return cout << "]";
}
// map<int, vector<int>> m;
// map<int, vector<pair<pair<int, int>, vector<int>>>> m2;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
// m[x].push_back(i);
}
struct S {
int l, r;
vector<int> inds;
S(int _l, int _r, vector<int> _inds): l(_l), r(_r), inds(_inds) {}
};
vector<pair<int, pair<int, vector<int>>>> stck;
stck.pb({MOD, {-1, {-1}}});
vector<S> ans;
vector<int> o(n, 0);
v.pb(MOD);
forn(i, n+1) {
while(stck.back().f < v[i]) {
auto s = stck.back();
stck.pop_back();
ans.pb(S(s.s.f, i-1, s.s.s));
}
if(stck.back().f == v[i]) {
stck.back().s.s.pb(i);
} else {
stck.pb({v[i], {stck.back().s.s.back()+1, {i}}});
}
}
// for(auto a: ans) {
// cout << a.l << " " << a.r << " " << a.inds << "\n";
// }
reverse(ans.begin(), ans.end());
int cur_h = 2 * n;
for (auto a: ans) {
// cout << a.r << " " << a.l << " " << a.inds << endl;
if (a.inds[0] == a.l || a.inds[a.inds.size() - 1] == a.r) {
int i = 0;
while(i < a.inds.size() && a.inds[i] == a.l + i) {
o[a.l + i] = cur_h - i;
i ++;
}
int j = 0;
if (i != a.inds.size()) {
while(j < a.inds.size() && a.inds[a.inds.size() - 1 - j] == a.r - j) {
o[a.r - j] = cur_h - j;
j++;
}
}
if (i + j < a.inds.size()) {
int mdx = a.inds[i];
o[mdx] = cur_h - i - j;
}
cur_h -= i + j + 1;
}
else {
for (auto idx: a.inds) {
o[idx] = cur_h;
}
cur_h --;
}
}
// cout << o << endl;
for (int i = 0; i < n; i++) {
cout << o[i] << " ";
}
cout << endl;
// priority_queue<pair<int, pair<int, vector<int>>>> q;
// for (int i = 0; i < n; i++) {
// while(!q.empty() && q.top().first < v[i]) {
// auto p = q.top();
// q.pop();
// m2[p.first].push_back(make_pair(make_pair(p.second.first, i - 1), p.second.second));
// }
// if (!q.empty() && q.top().first == v[i]) {
// q.top().second.second.push_back(i);
// }
// else if (!q.empty()) {
// }
// }
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
6 3 3 4 2 5 1
output:
6 5 9 8 12 11
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
4 3 3 3 3
output:
8 7 6 5
result:
ok
Test #3:
score: -100
Wrong Answer
time: 45ms
memory: 18908kb
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:
185488 185487 185486 185485 185499 185492 185491 185490 185498 185494 185497 185496 185509 185508 185507 185506 185501 185504 185503 185508 185528 185512 185511 185519 185515 185514 185518 185517 185528 185521 185527 185523 185526 185525 185541 185540 185530 185538 185537 185536 185535 185534 185533...
result:
wrong answer Integer 0 violates the range [1, 10^9]