QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#466733 | #8837. Increasing Income | USP_USP_USP# | WA | 0ms | 3624kb | C++20 | 2.8kb | 2024-07-08 06:29:42 | 2024-07-08 06:29:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define pb push_back
#define all(v) (v).begin(), (v).end()
void dbg_out() { cerr << endl; }
template<typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
const int MAXN = 2e5+5;
pair<int,int> seg[4*MAXN];
void build(int r, int i, int j){
if(i == j){
seg[r] = {0,i};
}else{
int m = (i+j)/2;
build(2*r,i,m);
build(2*r+1,m+1,j);
seg[r] = max(seg[2*r],seg[2*r+1]);
}
}
void update(int r, int i, int j, int p, int v){
if(i == j){
seg[r] = {v,i};
}else{
int m = (i+j)/2;
if(p <= m) update(2*r,i,m,p,v);
else update(2*r+1,m+1,j,p,v);
seg[r] = max(seg[2*r],seg[2*r+1]);
}
}
pair<int,int> query(int r, int i, int j, int a, int b){
if(i > b || a > j){
pair<int,int> aux = {0,0};
return aux;
}
if(a <= i && j <= b) return seg[r];
int m = (i+j)/2;
auto L = query(2*r,i,m,a,b);
auto R = query(2*r+1,m+1,j,a,b);
return max(L,R);
}
void solve() {
int n;
cin >> n;
build(1,0,n-1);
vector<int> p(n);
vector<int> b(n);
for(int i = 0; i < n; i++){
cin >> p[i];
p[i]--;
b[p[i]] = i;
}
vector<int> par(n,-1);
vector<int> dp(n);
for(int i = 0; i < n; i++){
if(p[i]){
auto ret = query(1,0,n-1,0,p[i]-1);
if(ret.first == 0){
update(1,0,n-1,p[i],1);
dp[i] = 1;
}else{
update(1,0,n-1,p[i],ret.first+1);
par[i] = b[ret.second];
dp[i] = ret.first+1;
}
}else{
update(1,0,n-1,p[i],1);
dp[i] = 1;
}
}
int best = 0;
for(int i = 0; i < n; i++){
if(dp[best] < dp[i]){
best = i;
}
}
vector<int> lis;
int eu = best;
while(eu != -1){
lis.push_back(eu);
eu = par[eu];
}
reverse(lis.begin(),lis.end());
vector<int> esta(n);
int sz = lis.size();
for(auto x : lis) esta[x] = 1;
vector<vector<int>> importai(sz), importapi(sz);
{
for(int i = 0; i < n; i++) if(!esta[i]){
int l = 0;
int r = sz-1;
while(l < r){
int m =(l+r+1)/2;
int id = lis[m];
if(id > i && p[id] > p[i]){
r = m-1;
}else{
l = m;
}
}
int id = lis[l];
if(id > i){
importai[l].push_back(i);
}else{
importapi[l].push_back(i);
}
}
}
vector<int> ans;
for(int i = 0; i < sz; i++){
ans.push_back(lis[i]);
{
vector<pair<int,int>> v;
for(auto x : importai[i]){
v.push_back({x,x});
}
sort(v.begin(),v.end());
for(auto [x,y] : v) ans.push_back(y);
}
{
vector<pair<int,int>> v;
for(auto x : importapi[i]){
v.push_back({p[x],x});
}
sort(v.begin(),v.end());
for(auto [x,y] : v) ans.push_back(y);
}
}
for(auto x : ans){
cout << x+1 << ' ';
}
cout << '\n';
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int t;
cin >> t;
while(t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
3 3 1 2 3 4 2 4 3 1 5 1 5 2 4 3
output:
1 2 3 1 2 4 3 1 3 4 2 5
result:
wrong answer Jury found better answer than participant (test case 2)