QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#458331 | #8837. Increasing Income | ucup-team1338# | WA | 3ms | 11676kb | C++20 | 1.3kb | 2024-06-29 16:41:44 | 2024-06-29 16:41:45 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N=1000013;
const int mod=998244353;
int p[N],ip[N];
int g[N],pre[N];
vector<int>v[200012];
void solve(){
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>p[i],ip[p[i]]=i,g[i]=0,v[i].clear();
vector<int>o,x;
for(int i=1;i<=n;i++){
if(o.empty()||o.back()<p[i]){
o.push_back(p[i]);
if(o.size()>1)pre[p[i]]=o[o.size()-2];
}
auto id=std::lower_bound(o.begin(), o.end(), p[i])-o.begin();
o[id]=p[i];
}
int s=(int)o.size();
for(int i=s-2;~i;i--)o[i]=pre[o[i+1]];
for(int i=0;i<s;i++)x.push_back(ip[o[i]]),g[x.back()]=1;
for(int i=1;i<=n;i++)if(!g[i]){
auto id=std::lower_bound(o.begin(), o.end(),p[i])-o.begin();
auto id2=std::lower_bound(x.begin(),x.end(),i)-x.begin();
v[max(id,id2)].push_back(i);
}
for(int i=0;i<s;i++){
cout<<x[i]<<' ';
std::sort(v[i+1].begin(), v[i+1].end(),[&](int f,int g){
if((f>x[i])!=(g>x[i]))return ((f>x[i])<(g>x[i]));
if(f>x[i])return f<g;
return p[f]<p[g];
});
for(auto y:v[i+1])cout<<y<<' ';
}
cout<<'\n';
}
int main(){
ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11664kb
input:
3 3 1 2 3 4 2 4 3 1 5 1 5 2 4 3
output:
1 2 3 1 3 2 4 1 3 5 4 2
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 11676kb
input:
153 4 2 4 3 1 4 1 4 2 3 5 2 1 4 5 3 5 1 4 5 3 2 4 1 3 2 4 5 1 5 2 4 3 5 5 3 1 2 4 5 4 1 2 5 3 5 1 2 5 3 4 5 3 1 4 2 5 5 5 4 2 3 1 5 2 1 5 4 3 5 3 4 1 5 2 5 1 4 3 5 2 5 5 1 3 4 2 5 5 3 2 4 1 5 1 5 3 2 4 5 2 4 3 1 5 5 1 5 4 3 2 5 1 2 4 5 3 5 4 2 5 3 1 5 1 3 5 2 4 5 3 1 4 5 2 3 2 1 3 5 1 2 4 3 5 5 5 1 ...
output:
0 1 3 2 4 0 1 3 4 2 2 1 3 4 5 1 2 3 4 5 0 1 3 2 4 0 1 3 5 4 2 3 4 2 5 1 0 2 3 5 1 4 0 1 2 4 5 3 2 4 1 3 5 3 4 2 1 5 1 2 5 4 3 1 2 3 4 5 5 3 2 4 2 3 4 1 5 3 2 4 1 5 1 4 3 5 2 4 1 3 2 5 1 5 4 3 2 1 2 3 4 5 5 2 4 1 3 1 4 2 5 3 2 1 3 4 5 2 1 3 0 1 2 4 3 5 0 2 3 5 4 1 3 4 1 5 2 ...
result:
wrong answer Integer element q[1] equals to 0, violates the range [1, 4] (test case 1)