Submission #1693482
Source Code Expand
#include<queue> #include<cstdio> #include<cstring> #define inf 2e8 #define maxn 500010 #define maxm 1000010 #define min(x,y) (x)<(y)?(x):(y) using namespace std; int to[maxm],nxt[maxm],mn[maxm]; 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,1,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 | 0 |
Code Size | 1690 Byte |
Status | RE |
Exec Time | 5256 ms |
Memory | 23168 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:49: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:52: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 | 0 / 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 | 10620 KB |
001.txt | AC | 3 ms | 10496 KB |
002.txt | AC | 4 ms | 12544 KB |
003.txt | AC | 4 ms | 12544 KB |
004.txt | AC | 4 ms | 12544 KB |
005.txt | AC | 5 ms | 12672 KB |
006.txt | AC | 4 ms | 12544 KB |
007.txt | AC | 4 ms | 12544 KB |
008.txt | AC | 4 ms | 12544 KB |
009.txt | AC | 5 ms | 12544 KB |
010.txt | AC | 5 ms | 12544 KB |
011.txt | AC | 5 ms | 12544 KB |
012.txt | AC | 5 ms | 12544 KB |
013.txt | AC | 5 ms | 12544 KB |
014.txt | AC | 5 ms | 12544 KB |
015.txt | AC | 5 ms | 12544 KB |
016.txt | AC | 5 ms | 12544 KB |
017.txt | AC | 5 ms | 12544 KB |
018.txt | AC | 5 ms | 12544 KB |
019.txt | AC | 5 ms | 12544 KB |
020.txt | AC | 4 ms | 12544 KB |
021.txt | AC | 4 ms | 12544 KB |
022.txt | AC | 5 ms | 12544 KB |
023.txt | AC | 5 ms | 12544 KB |
024.txt | AC | 4 ms | 12544 KB |
025.txt | AC | 5 ms | 12544 KB |
026.txt | AC | 5 ms | 12544 KB |
027.txt | AC | 4 ms | 12544 KB |
028.txt | AC | 4 ms | 12544 KB |
029.txt | AC | 4 ms | 10496 KB |
030.txt | AC | 5 ms | 12544 KB |
031.txt | AC | 5 ms | 12544 KB |
032.txt | AC | 5 ms | 12544 KB |
033.txt | AC | 5 ms | 12544 KB |
034.txt | AC | 5 ms | 12544 KB |
035.txt | AC | 5 ms | 12544 KB |
036.txt | AC | 5 ms | 12544 KB |
037.txt | AC | 5 ms | 12544 KB |
038.txt | AC | 5 ms | 12544 KB |
039.txt | WA | 651 ms | 22772 KB |
040.txt | TLE | 5255 ms | 19840 KB |
041.txt | WA | 560 ms | 23168 KB |
042.txt | RE | 657 ms | 23168 KB |
043.txt | RE | 655 ms | 23040 KB |
044.txt | RE | 583 ms | 22912 KB |
045.txt | WA | 643 ms | 23040 KB |
046.txt | RE | 606 ms | 19584 KB |
047.txt | RE | 638 ms | 23040 KB |
048.txt | WA | 557 ms | 23168 KB |
049.txt | AC | 192 ms | 18944 KB |
050.txt | RE | 378 ms | 19584 KB |
051.txt | AC | 239 ms | 19200 KB |
052.txt | RE | 602 ms | 22144 KB |
053.txt | AC | 72 ms | 11512 KB |
054.txt | RE | 448 ms | 20096 KB |
055.txt | AC | 5 ms | 12544 KB |
056.txt | AC | 49 ms | 13184 KB |
057.txt | AC | 239 ms | 19328 KB |
058.txt | AC | 60 ms | 13184 KB |
059.txt | WA | 425 ms | 19696 KB |
060.txt | RE | 466 ms | 19584 KB |
061.txt | WA | 665 ms | 22772 KB |
062.txt | RE | 467 ms | 19584 KB |
063.txt | WA | 668 ms | 22520 KB |
064.txt | TLE | 5256 ms | 20220 KB |
065.txt | WA | 676 ms | 22648 KB |
066.txt | RE | 501 ms | 22912 KB |
067.txt | WA | 661 ms | 22780 KB |
068.txt | TLE | 5256 ms | 20220 KB |
069.txt | TLE | 5255 ms | 18944 KB |
070.txt | TLE | 5255 ms | 18944 KB |
071.txt | TLE | 5256 ms | 19584 KB |
072.txt | WA | 341 ms | 22392 KB |
073.txt | TLE | 5256 ms | 19200 KB |
074.txt | TLE | 5255 ms | 19832 KB |
075.txt | RE | 472 ms | 19584 KB |
076.txt | RE | 474 ms | 19584 KB |
077.txt | TLE | 5256 ms | 19456 KB |
078.txt | TLE | 5255 ms | 19200 KB |
079.txt | AC | 105 ms | 18176 KB |
080.txt | AC | 17 ms | 12800 KB |
081.txt | AC | 31 ms | 13056 KB |
082.txt | AC | 204 ms | 19328 KB |
083.txt | AC | 59 ms | 13440 KB |
084.txt | AC | 59 ms | 13440 KB |
085.txt | AC | 50 ms | 13312 KB |
086.txt | AC | 15 ms | 12800 KB |
087.txt | AC | 102 ms | 18048 KB |
088.txt | AC | 58 ms | 13568 KB |
089.txt | TLE | 5255 ms | 14836 KB |
090.txt | TLE | 5255 ms | 18816 KB |
sample-01.txt | AC | 4 ms | 12544 KB |
sample-02.txt | AC | 3 ms | 10496 KB |
sample-03.txt | AC | 4 ms | 12544 KB |