Submission #1693490
Source Code Expand
#include<queue> #include<cstdio> #include<cstring> #define inf 2e8 #define maxn 500010 #define min(x,y) (x)<(y)?(x):(y) using namespace std; int to[maxn*2],nxt[maxn*2],mn[maxn*4]; int a[maxn],b[maxn],d[maxn]; int first[maxn]; int n,k,cnt; priority_queue<int>q; void add(int x,int y) { to[++cnt]=y; nxt[cnt]=first[x]; first[x]=cnt; d[y]++; } void change(int x,int l,int r,int p,int v) { if(l==r) { mn[x]=v; return; } int mid=(l+r)>>1; if(p<=mid) change(x<<1,l,mid,p,v); else change(x<<1|1,mid+1,r,p,v); mn[x]=min(mn[x<<1],mn[x<<1|1]); } int query(int x,int l,int r,int s,int t) { if(s<=l&&r<=t) return mn[x]; int mid=(l+r)>>1,ans=inf; if(s<=mid) ans=min(ans,query(x<<1,l,mid,s,t)); if(t>mid) ans=min(ans,query(x<<1|1,mid+1,r,s,t)); return ans; } int main() { int x; scanf("%d%d",&n,&k); memset(mn,15,sizeof(mn)); for(int i=1;i<=n;i++) scanf("%d",&b[i]),a[b[i]]=i; for(int i=n;i;i--) { x=query(1,1,n,a[i]-k+1,a[i]); if(x<=n) add(a[x],a[i]); x=query(1,1,n,a[i],a[i]+k-1); if(x<=n) add(a[x],a[i]); change(1,1,n,a[i],i); } for(int i=1;i<=n;i++) if(!d[i]) q.push(i); for(int i=n;i;i--) { b[i]=x=q.top(); q.pop(); for(int j=first[x];j;j=nxt[j]) if((--d[to[j]])==0) q.push(to[j]); } for(int i=1;i<=n;i++) a[b[i]]=i; for(int i=1;i<=n;i++) printf("%d\n",a[i]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Wide Swap |
User | Rushfinen |
Language | C++14 (GCC 5.4.1) |
Score | 2000 |
Code Size | 1675 Byte |
Status | AC |
Exec Time | 607 ms |
Memory | 27008 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:48:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&n,&k); ^ ./Main.cpp:51:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&b[i]),a[b[i]]=i; ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 2000 / 2000 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, 064.txt, 065.txt, 066.txt, 067.txt, 068.txt, 069.txt, 070.txt, 071.txt, 072.txt, 073.txt, 074.txt, 075.txt, 076.txt, 077.txt, 078.txt, 079.txt, 080.txt, 081.txt, 082.txt, 083.txt, 084.txt, 085.txt, 086.txt, 087.txt, 088.txt, 089.txt, 090.txt, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 4 ms | 14592 KB |
001.txt | AC | 4 ms | 14592 KB |
002.txt | AC | 5 ms | 16640 KB |
003.txt | AC | 5 ms | 16640 KB |
004.txt | AC | 5 ms | 16640 KB |
005.txt | AC | 5 ms | 16640 KB |
006.txt | AC | 5 ms | 16640 KB |
007.txt | AC | 5 ms | 16640 KB |
008.txt | AC | 5 ms | 16640 KB |
009.txt | AC | 6 ms | 16640 KB |
010.txt | AC | 6 ms | 16640 KB |
011.txt | AC | 6 ms | 16640 KB |
012.txt | AC | 6 ms | 16640 KB |
013.txt | AC | 6 ms | 16640 KB |
014.txt | AC | 6 ms | 16640 KB |
015.txt | AC | 6 ms | 16640 KB |
016.txt | AC | 6 ms | 16640 KB |
017.txt | AC | 6 ms | 16640 KB |
018.txt | AC | 6 ms | 16640 KB |
019.txt | AC | 6 ms | 16640 KB |
020.txt | AC | 5 ms | 16640 KB |
021.txt | AC | 5 ms | 16640 KB |
022.txt | AC | 6 ms | 16640 KB |
023.txt | AC | 6 ms | 16640 KB |
024.txt | AC | 6 ms | 16640 KB |
025.txt | AC | 6 ms | 16640 KB |
026.txt | AC | 6 ms | 16640 KB |
027.txt | AC | 5 ms | 16640 KB |
028.txt | AC | 5 ms | 16640 KB |
029.txt | AC | 5 ms | 14592 KB |
030.txt | AC | 6 ms | 16640 KB |
031.txt | AC | 6 ms | 16640 KB |
032.txt | AC | 6 ms | 16640 KB |
033.txt | AC | 6 ms | 16640 KB |
034.txt | AC | 6 ms | 16640 KB |
035.txt | AC | 6 ms | 16640 KB |
036.txt | AC | 6 ms | 16640 KB |
037.txt | AC | 6 ms | 16640 KB |
038.txt | AC | 6 ms | 16640 KB |
039.txt | AC | 430 ms | 26868 KB |
040.txt | AC | 531 ms | 27008 KB |
041.txt | AC | 607 ms | 27008 KB |
042.txt | AC | 565 ms | 27008 KB |
043.txt | AC | 554 ms | 27008 KB |
044.txt | AC | 458 ms | 27008 KB |
045.txt | AC | 452 ms | 26880 KB |
046.txt | AC | 532 ms | 27008 KB |
047.txt | AC | 530 ms | 27008 KB |
048.txt | AC | 469 ms | 26880 KB |
049.txt | AC | 193 ms | 23040 KB |
050.txt | AC | 282 ms | 23680 KB |
051.txt | AC | 231 ms | 23296 KB |
052.txt | AC | 492 ms | 26112 KB |
053.txt | AC | 73 ms | 15608 KB |
054.txt | AC | 341 ms | 24192 KB |
055.txt | AC | 6 ms | 16640 KB |
056.txt | AC | 51 ms | 17280 KB |
057.txt | AC | 226 ms | 23424 KB |
058.txt | AC | 59 ms | 17280 KB |
059.txt | AC | 404 ms | 19952 KB |
060.txt | AC | 395 ms | 27008 KB |
061.txt | AC | 434 ms | 26868 KB |
062.txt | AC | 392 ms | 27008 KB |
063.txt | AC | 432 ms | 26616 KB |
064.txt | AC | 416 ms | 27008 KB |
065.txt | AC | 446 ms | 26616 KB |
066.txt | AC | 402 ms | 27008 KB |
067.txt | AC | 434 ms | 26492 KB |
068.txt | AC | 397 ms | 27008 KB |
069.txt | AC | 384 ms | 26112 KB |
070.txt | AC | 410 ms | 26112 KB |
071.txt | AC | 378 ms | 26752 KB |
072.txt | AC | 342 ms | 26488 KB |
073.txt | AC | 413 ms | 26368 KB |
074.txt | AC | 350 ms | 26868 KB |
075.txt | AC | 426 ms | 26880 KB |
076.txt | AC | 426 ms | 26880 KB |
077.txt | AC | 412 ms | 26624 KB |
078.txt | AC | 408 ms | 26368 KB |
079.txt | AC | 105 ms | 20224 KB |
080.txt | AC | 18 ms | 16896 KB |
081.txt | AC | 33 ms | 17152 KB |
082.txt | AC | 205 ms | 23424 KB |
083.txt | AC | 60 ms | 17536 KB |
084.txt | AC | 61 ms | 17536 KB |
085.txt | AC | 51 ms | 17408 KB |
086.txt | AC | 16 ms | 16896 KB |
087.txt | AC | 103 ms | 22144 KB |
088.txt | AC | 59 ms | 17664 KB |
089.txt | AC | 337 ms | 19952 KB |
090.txt | AC | 353 ms | 26112 KB |
sample-01.txt | AC | 5 ms | 16640 KB |
sample-02.txt | AC | 4 ms | 14592 KB |
sample-03.txt | AC | 5 ms | 16640 KB |