Submission #3418124
Source Code Expand
#include<bits/stdc++.h> using namespace std; const int N = 5e5 + 10; const int inf = 0x3f3f3f3f; int n, k, E; int p[N], q[N]; int tr[N << 2], ans1[N], ans2[N]; int fir[N], deg[N], nex[N << 1], arr[N << 1]; priority_queue<int, vector<int>, greater<int> > Q; inline void Add_Edge(int x, int y) { // cout << x << ' ' << y << endl; nex[++E] = fir[x]; fir[x] = E; arr[E] = y; deg[y]++; } void Updata(int x, int l, int r, int pos, int v) { if (l == r) return (void) (tr[x] = v); int mid = (l + r) >> 1; if (mid >= pos) Updata(x << 1, l, mid, pos, v); if (mid < pos) Updata(x << 1 | 1, mid + 1, r, pos, v); tr[x] = min(tr[x << 1], tr[x << 1 | 1]); } int Query(int x, int l, int r, int ql, int qr) { if (ql <= l && r <= qr) return tr[x]; int mid = (l + r) >> 1, ans = 0x3f3f3f3f; if (mid >= ql) ans = min(ans, Query(x << 1, l, mid, ql, qr)); if (mid < qr) ans = min(ans, Query(x << 1 | 1, mid + 1, r, ql, qr)); return ans; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) { scanf("%d", &p[i]); q[p[i]] = i; } /* for (int i = 1; i <= n; ++i) cout << q[i] << ' '; puts("");*/ memset(tr, 0x3f, sizeof tr); for (int i = n; i >= 1; --i) { int x = Query(1, 1, n, min(n, q[i] + 1), min(n, q[i] + k - 1)); int y = Query(1, 1, n, max(1, q[i] - k + 1), max(1, q[i] - 1)); // cout << i << ' ' << x << ' ' << y << endl; if (x != inf) Add_Edge(q[i], q[x]); if (y != inf) Add_Edge(q[i], q[y]); Updata(1, 1, n, q[i], i); } for (int i = 1; i <= n; ++i) if (!deg[i]) Q.push(i); int cnt = 0; while (!Q.empty()) { int x = Q.top(); Q.pop(); for (int i = fir[x]; i; i = nex[i]) { if (--deg[arr[i]] == 0) Q.push(arr[i]); } ans1[++cnt] = x; } for (int i = 1; i <= n; ++i) ans2[ans1[i]] = i; /* for (int i = 1; i <= n; ++i) cout << ans1[i] << ' '; puts("");*/ for (int i = 1; i <= n; ++i) printf("%d\n", ans2[i]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Wide Swap |
User | Vexoben |
Language | C++14 (GCC 5.4.1) |
Score | 2000 |
Code Size | 1965 Byte |
Status | AC |
Exec Time | 492 ms |
Memory | 31604 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:39:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &n, &k); ^ ./Main.cpp:41:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &p[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 | 5 ms | 16640 KB |
001.txt | AC | 5 ms | 16640 KB |
002.txt | AC | 6 ms | 22784 KB |
003.txt | AC | 6 ms | 22784 KB |
004.txt | AC | 6 ms | 22784 KB |
005.txt | AC | 6 ms | 22784 KB |
006.txt | AC | 6 ms | 22784 KB |
007.txt | AC | 6 ms | 22784 KB |
008.txt | AC | 6 ms | 22784 KB |
009.txt | AC | 7 ms | 22784 KB |
010.txt | AC | 7 ms | 22784 KB |
011.txt | AC | 7 ms | 22784 KB |
012.txt | AC | 7 ms | 22784 KB |
013.txt | AC | 7 ms | 22784 KB |
014.txt | AC | 7 ms | 22784 KB |
015.txt | AC | 7 ms | 22784 KB |
016.txt | AC | 7 ms | 22784 KB |
017.txt | AC | 7 ms | 22784 KB |
018.txt | AC | 7 ms | 22784 KB |
019.txt | AC | 7 ms | 22784 KB |
020.txt | AC | 6 ms | 22784 KB |
021.txt | AC | 6 ms | 22784 KB |
022.txt | AC | 7 ms | 22784 KB |
023.txt | AC | 7 ms | 22784 KB |
024.txt | AC | 7 ms | 22784 KB |
025.txt | AC | 7 ms | 22784 KB |
026.txt | AC | 7 ms | 22784 KB |
027.txt | AC | 7 ms | 22784 KB |
028.txt | AC | 6 ms | 22784 KB |
029.txt | AC | 6 ms | 16640 KB |
030.txt | AC | 7 ms | 22784 KB |
031.txt | AC | 7 ms | 22784 KB |
032.txt | AC | 7 ms | 22784 KB |
033.txt | AC | 7 ms | 22784 KB |
034.txt | AC | 7 ms | 22784 KB |
035.txt | AC | 7 ms | 22784 KB |
036.txt | AC | 7 ms | 22784 KB |
037.txt | AC | 7 ms | 22784 KB |
038.txt | AC | 7 ms | 22784 KB |
039.txt | AC | 409 ms | 31604 KB |
040.txt | AC | 452 ms | 30848 KB |
041.txt | AC | 483 ms | 30848 KB |
042.txt | AC | 491 ms | 30848 KB |
043.txt | AC | 485 ms | 30848 KB |
044.txt | AC | 419 ms | 30848 KB |
045.txt | AC | 419 ms | 31104 KB |
046.txt | AC | 488 ms | 30848 KB |
047.txt | AC | 492 ms | 30848 KB |
048.txt | AC | 422 ms | 30976 KB |
049.txt | AC | 176 ms | 27776 KB |
050.txt | AC | 254 ms | 28672 KB |
051.txt | AC | 214 ms | 28288 KB |
052.txt | AC | 449 ms | 30336 KB |
053.txt | AC | 63 ms | 17656 KB |
054.txt | AC | 315 ms | 29056 KB |
055.txt | AC | 7 ms | 22784 KB |
056.txt | AC | 49 ms | 25600 KB |
057.txt | AC | 210 ms | 28288 KB |
058.txt | AC | 56 ms | 25728 KB |
059.txt | AC | 347 ms | 22768 KB |
060.txt | AC | 365 ms | 30848 KB |
061.txt | AC | 418 ms | 31604 KB |
062.txt | AC | 375 ms | 30848 KB |
063.txt | AC | 403 ms | 31352 KB |
064.txt | AC | 364 ms | 30848 KB |
065.txt | AC | 410 ms | 31352 KB |
066.txt | AC | 360 ms | 30848 KB |
067.txt | AC | 403 ms | 31228 KB |
068.txt | AC | 359 ms | 30848 KB |
069.txt | AC | 357 ms | 30848 KB |
070.txt | AC | 379 ms | 30848 KB |
071.txt | AC | 350 ms | 30848 KB |
072.txt | AC | 322 ms | 31352 KB |
073.txt | AC | 378 ms | 30848 KB |
074.txt | AC | 337 ms | 31604 KB |
075.txt | AC | 389 ms | 30848 KB |
076.txt | AC | 388 ms | 30848 KB |
077.txt | AC | 379 ms | 30848 KB |
078.txt | AC | 378 ms | 30848 KB |
079.txt | AC | 97 ms | 26624 KB |
080.txt | AC | 18 ms | 23040 KB |
081.txt | AC | 32 ms | 25344 KB |
082.txt | AC | 188 ms | 28288 KB |
083.txt | AC | 57 ms | 25856 KB |
084.txt | AC | 58 ms | 25856 KB |
085.txt | AC | 48 ms | 25728 KB |
086.txt | AC | 16 ms | 23040 KB |
087.txt | AC | 96 ms | 26752 KB |
088.txt | AC | 58 ms | 25856 KB |
089.txt | AC | 286 ms | 22768 KB |
090.txt | AC | 327 ms | 30848 KB |
sample-01.txt | AC | 6 ms | 22784 KB |
sample-02.txt | AC | 5 ms | 16640 KB |
sample-03.txt | AC | 6 ms | 22784 KB |