Submission #67656630
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=501000;
template<class T>
struct BIT {
T c[N];
int size;
void init(int s) {
size = s;
for (int i = 1; i <= s; i++) c[i] = 0;
}
T query(int x) { // 1 ... x
assert(x <= size);
T s = 0;
for (; x; x -= x & (-x)) {
s = max(s, c[x]);
}
return s;
}
void modify(int x, T s) { // a[x] += s
assert(x != 0);
for (; x <= size; x += x & (-x)) {
c[x] = max(c[x], s);
}
}
};
int n,p[N],dp[N],pos[N],val[N];
VI pc[N];
BIT<int> c;
struct node {
int fg,s;
}nd[4*N];
void upd(int p) {
nd[p].s=min(nd[p+p].s,nd[p+p+1].s);
}
void setf(int p,int v) {
}
void build(int p,int l,int r) {
nd[p].fg=0;
if (l==r) {
nd[p].s=1<<30;
} else {
int md=(l+r)>>1;
build(p+p,l,md);
build(p+p+1,md+1,r);
upd(p);
}
}
void push(int p) {
if (nd[p].fg) {
setf(p+p,nd[p].fg);
setf(p+p+1,nd[p].fg);
nd[p].fg=0;
}
}
int query(int p,int l,int r,int tl,int tr) {
if (tl==l&&tr==r) return nd[p].s;
else {
push(p);
int md=(l+r)>>1;
if (tr<=md) return query(p+p,l,md,tl,tr);
else if (tl>md) return query(p+p+1,md+1,r,tl,tr);
else return min(query(p+p,l,md,tl,md),query(p+p+1,md+1,r,md+1,tr));
}
}
void change(int p,int l,int r,int x,int v) {
if (p==1) {
//printf("change %d %d\n",x,v);
}
if (l==r) nd[p].s=v;
else {
push(p);
int md=(l+r)>>1;
if (x<=md) change(p+p,l,md,x,v);
else change(p+p+1,md+1,r,x,v);
upd(p);
}
}
void solve() {
scanf("%d",&n);
c.init(n);
rep(i,1,n+1) pc[i].clear();
rep(i,1,n+1) {
scanf("%d",&p[i]);
pos[p[i]]=i;
}
int M=0;
per(i,1,n+1) {
dp[i]=c.query(n+1-p[i])+1;
M=max(M,dp[i]);
c.modify(n+1-p[i],dp[i]);
val[p[i]]=dp[i];
pc[dp[i]].pb(p[i]);
}
VI v(p+1,p+n+1);
VI ans;
build(1,1,n);
set<int> rem;
rep(i,1,n+1) rem.insert(i);
per(m,1,M+1) {
for (auto x:pc[m]) if (rem.count(x)) change(1,1,n,pos[x],x);
auto it=*rem.begin();
change(1,1,n,pos[it],it);
int ps=n;
VI pc;
while (ps>=1) {
auto t=query(1,1,n,1,ps);
if (t>n) break;
//printf("!!! %d\n",t);
rem.erase(t);
pc.pb(t);
change(1,1,n,pos[t],1<<30);
ps=pos[t]-1;
}
reverse(all(pc));
ans.insert(ans.end(),all(pc));
}
for (auto x:ans) printf("%d ",x);
puts("");
}
int _;
int main() {
for (scanf("%d",&_);_;_--) {
solve();
}
}
Submission Info
| Submission Time |
|
| Task |
A - LIS Keeping Swaps |
| User |
apiad |
| Language |
C++ 20 (gcc 12.2) |
| Score |
800 |
| Code Size |
3077 Byte |
| Status |
AC |
| Exec Time |
302 ms |
| Memory |
38508 KiB |
Compile Error
Main.cpp: In function ‘void setf(int, int)’:
Main.cpp:61:15: warning: unused parameter ‘p’ [-Wunused-parameter]
61 | void setf(int p,int v) {
| ~~~~^
Main.cpp:61:21: warning: unused parameter ‘v’ [-Wunused-parameter]
61 | void setf(int p,int v) {
| ~~~~^
Main.cpp: In function ‘void solve()’:
Main.cpp:107:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
107 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
Main.cpp:111:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
111 | scanf("%d",&p[i]);
| ~~~~~^~~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:150:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
150 | for (scanf("%d",&_);_;_--) {
| ~~~~~^~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
800 / 800 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-001.txt |
| All |
00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt, 01-043.txt, 01-044.txt, 01-045.txt, 01-046.txt, 01-047.txt, 01-048.txt, 01-049.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-001.txt |
AC |
3 ms |
3688 KiB |
| 01-001.txt |
AC |
63 ms |
3924 KiB |
| 01-002.txt |
AC |
63 ms |
3672 KiB |
| 01-003.txt |
AC |
63 ms |
3716 KiB |
| 01-004.txt |
AC |
63 ms |
3868 KiB |
| 01-005.txt |
AC |
63 ms |
3864 KiB |
| 01-006.txt |
AC |
63 ms |
3836 KiB |
| 01-007.txt |
AC |
63 ms |
3688 KiB |
| 01-008.txt |
AC |
63 ms |
3872 KiB |
| 01-009.txt |
AC |
63 ms |
3684 KiB |
| 01-010.txt |
AC |
62 ms |
3692 KiB |
| 01-011.txt |
AC |
65 ms |
3788 KiB |
| 01-012.txt |
AC |
63 ms |
3704 KiB |
| 01-013.txt |
AC |
63 ms |
3688 KiB |
| 01-014.txt |
AC |
63 ms |
3864 KiB |
| 01-015.txt |
AC |
34 ms |
3712 KiB |
| 01-016.txt |
AC |
80 ms |
3584 KiB |
| 01-017.txt |
AC |
91 ms |
3772 KiB |
| 01-018.txt |
AC |
115 ms |
3920 KiB |
| 01-019.txt |
AC |
121 ms |
3924 KiB |
| 01-020.txt |
AC |
141 ms |
4020 KiB |
| 01-021.txt |
AC |
149 ms |
4996 KiB |
| 01-022.txt |
AC |
181 ms |
6364 KiB |
| 01-023.txt |
AC |
195 ms |
11492 KiB |
| 01-024.txt |
AC |
297 ms |
28184 KiB |
| 01-025.txt |
AC |
302 ms |
28180 KiB |
| 01-026.txt |
AC |
204 ms |
38508 KiB |
| 01-027.txt |
AC |
180 ms |
26000 KiB |
| 01-028.txt |
AC |
201 ms |
38508 KiB |
| 01-029.txt |
AC |
182 ms |
25980 KiB |
| 01-030.txt |
AC |
210 ms |
38024 KiB |
| 01-031.txt |
AC |
188 ms |
26048 KiB |
| 01-032.txt |
AC |
204 ms |
31728 KiB |
| 01-033.txt |
AC |
190 ms |
27040 KiB |
| 01-034.txt |
AC |
206 ms |
32008 KiB |
| 01-035.txt |
AC |
192 ms |
26972 KiB |
| 01-036.txt |
AC |
206 ms |
31724 KiB |
| 01-037.txt |
AC |
191 ms |
27224 KiB |
| 01-038.txt |
AC |
211 ms |
28576 KiB |
| 01-039.txt |
AC |
205 ms |
27624 KiB |
| 01-040.txt |
AC |
213 ms |
28468 KiB |
| 01-041.txt |
AC |
205 ms |
27752 KiB |
| 01-042.txt |
AC |
220 ms |
28472 KiB |
| 01-043.txt |
AC |
204 ms |
27476 KiB |
| 01-044.txt |
AC |
228 ms |
27676 KiB |
| 01-045.txt |
AC |
212 ms |
27196 KiB |
| 01-046.txt |
AC |
226 ms |
27684 KiB |
| 01-047.txt |
AC |
216 ms |
27552 KiB |
| 01-048.txt |
AC |
226 ms |
27544 KiB |
| 01-049.txt |
AC |
216 ms |
27280 KiB |