QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419978 | #7939. High Towers | gabrielwu | WA | 47ms | 19072kb | C++20 | 3.3kb | 2024-05-24 13:31:34 | 2024-05-24 13:31:35 |
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] + 100000000 << " ";
}
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: 0ms
memory: 3620kb
input:
6 3 3 4 2 5 1
output:
100000006 100000005 100000009 100000008 100000012 100000011
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
4 3 3 3 3
output:
100000008 100000007 100000006 100000005
result:
ok
Test #3:
score: -100
Wrong Answer
time: 47ms
memory: 19072kb
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:
100185488 100185487 100185486 100185485 100185499 100185492 100185491 100185490 100185498 100185494 100185497 100185496 100185509 100185508 100185507 100185506 100185501 100185504 100185503 100185508 100185528 100185512 100185511 100185519 100185515 100185514 100185518 100185517 100185528 100185521 ...
result:
wrong answer