QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462467 | #8837. Increasing Income | Afterlife | WA | 0ms | 3564kb | C++20 | 1.8kb | 2024-07-03 19:56:58 | 2024-07-03 19:56:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int n ;
int a[200005];
struct bit {
int c[200005];
void init() {
for(int i = 0;i <= n+1;i++) c[i] = 0;
}
void upd(int u,int v) {
while(u <= n) {
c[u] = max(c[u] , v) ;
u += (u&-u);
}
}
int qry(int x) {
int ans = 0;
while(x) {
ans = max(ans , c[x]) ;
x -= (x&-x);
}
return ans;
}
}b;
int f[200005];
bool cho[200005];
void solv() {
cin >> n;
b.init();
for(int i = 1;i <= n;i++) cin >> a[i];
int mx = 0 , lst = n + 1;
for(int i = 1;i <= n;i++) {
f[i] = b.qry(a[i]) + 1;
mx = max(mx , f[i]);
b.upd(a[i] , f[i]) ;
}
for(int i = n;i >= 1;i--) {
if(a[i] < lst && f[i] == mx) {
mx-- ; lst = a[i];
cho[i] = 1;
}
else cho[i] = 0;
}
mx = 0;
vector<pii> lft;
vector<pii> cur;
for(int i = 1;i <= n;i++) {
if(a[i] < mx) cho[i] = 1;
if(cho[i]) {mx = max(mx , a[i]) ; cur.push_back({mx , i}) ;}
else lft.push_back({a[i] , i}) ;
}
sort(lft.begin() , lft.end()) ; reverse(lft.begin() , lft.end()) ;
vector<int> ans;
int cid = cur.size() - 1;
for(int i = lft.size() - 1 ; i >= 0;i--) {
while(cid >= 0 && cur[cid].first > lft[i].first) {
ans.push_back(cur[cid].second) ;
cid--;
}
ans.push_back(lft[i].second) ;
}
while(cid >= 0) ans.push_back(cur[cid--].second) ;
reverse(ans.begin() , ans.end()) ;
for(auto x : ans) cout << x <<' ' ; cout << '\n';
}
int main() {
ios::sync_with_stdio(false) ; cin.tie(0) ;
int t;cin >> t;
while(t--) solv() ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
3 3 1 2 3 4 2 4 3 1 5 1 5 2 4 3
output:
1 2 3 1 3 4 2 1 3 5 2 4
result:
wrong answer Jury found better answer than participant (test case 3)