Submission #157134

# Submission time Handle Problem Language Result Execution time Memory
157134 2019-10-09T17:05:19 Z NachoLibre Arranging Shoes (IOI19_shoes) C++14
100 / 100
403 ms 275096 KB
#include <bits/stdc++.h>
using namespace std;

queue<int> q[2][200005];
bool bo[200005];
int ft[200005];

void gnk(int i) {
    while(i < 200005) {
        ++ft[i];
        i += (i & -i);
    }
}

int pay(int i) {
    int tp = 0;
    while(i > 0) {
        tp += ft[i];
        i -= (i & -i);
    }
    return tp;
}

long long count_swaps(vector<int> s) {
    long long rp = 0;
    int n = s.size(), payi = 0, a[n + 1];
    for(int i = 1; i <= n; ++i) {
        a[i] = s[i - 1];
    }
    for(int i = 1; i <= n; ++i) {
        if(a[i] < 0) q[0][-a[i]].push(i);
        else q[1][a[i]].push(i);
    }
    for(int i = 1; i <= n; ++i) {
        if(!bo[i]) {
            if(a[i] > 0) {
                q[1][a[i]].pop();
                rp += q[0][a[i]].front() - i - (pay(q[0][a[i]].front()) - payi);
                gnk(q[0][a[i]].front());
                bo[q[0][a[i]].front()] = 1;
                q[0][a[i]].pop();
            } else {
                q[0][-a[i]].pop();
                rp += q[1][-a[i]].front() - i - 1 - (pay(q[1][-a[i]].front()) - payi);
                gnk(q[1][-a[i]].front());
                bo[q[1][-a[i]].front()] = 1;
                q[1][-a[i]].pop();
            }
        } else {
            ++payi;
        }
    }
    return rp;
}
# Verdict Execution time Memory Grader output
1 Correct 299 ms 269676 KB Output is correct
2 Correct 281 ms 269684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 299 ms 269676 KB Output is correct
2 Correct 281 ms 269684 KB Output is correct
3 Correct 301 ms 269692 KB Output is correct
4 Correct 283 ms 269788 KB Output is correct
5 Correct 335 ms 269692 KB Output is correct
6 Correct 293 ms 269712 KB Output is correct
7 Correct 277 ms 269684 KB Output is correct
8 Correct 276 ms 269560 KB Output is correct
9 Correct 276 ms 269692 KB Output is correct
10 Correct 275 ms 269688 KB Output is correct
11 Correct 277 ms 269688 KB Output is correct
12 Correct 275 ms 269688 KB Output is correct
13 Correct 274 ms 269688 KB Output is correct
14 Correct 403 ms 269564 KB Output is correct
15 Correct 323 ms 269616 KB Output is correct
16 Correct 274 ms 269688 KB Output is correct
17 Correct 274 ms 269564 KB Output is correct
18 Correct 277 ms 269688 KB Output is correct
19 Correct 302 ms 269716 KB Output is correct
20 Correct 291 ms 269560 KB Output is correct
21 Correct 284 ms 269688 KB Output is correct
22 Correct 319 ms 269664 KB Output is correct
23 Correct 285 ms 269700 KB Output is correct
24 Correct 314 ms 269688 KB Output is correct
25 Correct 280 ms 269688 KB Output is correct
26 Correct 294 ms 269668 KB Output is correct
27 Correct 305 ms 269720 KB Output is correct
28 Correct 286 ms 269672 KB Output is correct
29 Correct 344 ms 269688 KB Output is correct
30 Correct 298 ms 269744 KB Output is correct
31 Correct 285 ms 269608 KB Output is correct
32 Correct 336 ms 269604 KB Output is correct
33 Correct 281 ms 269688 KB Output is correct
34 Correct 275 ms 269604 KB Output is correct
35 Correct 276 ms 269688 KB Output is correct
36 Correct 308 ms 269816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 299 ms 269676 KB Output is correct
2 Correct 281 ms 269684 KB Output is correct
3 Correct 327 ms 269604 KB Output is correct
4 Correct 342 ms 269724 KB Output is correct
5 Correct 328 ms 269592 KB Output is correct
6 Correct 278 ms 269660 KB Output is correct
7 Correct 278 ms 269688 KB Output is correct
8 Correct 289 ms 269612 KB Output is correct
9 Correct 278 ms 269644 KB Output is correct
10 Correct 279 ms 269592 KB Output is correct
11 Correct 278 ms 269688 KB Output is correct
12 Correct 279 ms 269628 KB Output is correct
13 Correct 275 ms 269608 KB Output is correct
14 Correct 278 ms 269560 KB Output is correct
15 Correct 276 ms 269600 KB Output is correct
16 Correct 277 ms 269760 KB Output is correct
17 Correct 276 ms 269604 KB Output is correct
18 Correct 299 ms 269776 KB Output is correct
19 Correct 301 ms 269660 KB Output is correct
20 Correct 305 ms 270192 KB Output is correct
21 Correct 306 ms 270104 KB Output is correct
22 Correct 348 ms 275064 KB Output is correct
23 Correct 334 ms 275064 KB Output is correct
24 Correct 335 ms 275064 KB Output is correct
25 Correct 333 ms 274448 KB Output is correct
26 Correct 328 ms 275064 KB Output is correct
27 Correct 330 ms 274936 KB Output is correct
28 Correct 346 ms 274552 KB Output is correct
29 Correct 333 ms 274592 KB Output is correct
30 Correct 358 ms 274544 KB Output is correct
31 Correct 338 ms 275096 KB Output is correct
32 Correct 335 ms 274524 KB Output is correct
33 Correct 394 ms 274296 KB Output is correct
34 Correct 386 ms 274552 KB Output is correct
35 Correct 274 ms 269624 KB Output is correct
36 Correct 275 ms 269560 KB Output is correct
37 Correct 324 ms 274552 KB Output is correct
38 Correct 328 ms 274680 KB Output is correct
39 Correct 353 ms 274524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 280 ms 269752 KB Output is correct
2 Correct 279 ms 269592 KB Output is correct
3 Correct 277 ms 269636 KB Output is correct
4 Correct 278 ms 269688 KB Output is correct
5 Correct 366 ms 273748 KB Output is correct
6 Correct 333 ms 273796 KB Output is correct
7 Correct 366 ms 273656 KB Output is correct
8 Correct 335 ms 274552 KB Output is correct
9 Correct 402 ms 273912 KB Output is correct
10 Correct 346 ms 273784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 299 ms 269676 KB Output is correct
2 Correct 281 ms 269684 KB Output is correct
3 Correct 301 ms 269692 KB Output is correct
4 Correct 283 ms 269788 KB Output is correct
5 Correct 335 ms 269692 KB Output is correct
6 Correct 293 ms 269712 KB Output is correct
7 Correct 277 ms 269684 KB Output is correct
8 Correct 276 ms 269560 KB Output is correct
9 Correct 276 ms 269692 KB Output is correct
10 Correct 275 ms 269688 KB Output is correct
11 Correct 277 ms 269688 KB Output is correct
12 Correct 275 ms 269688 KB Output is correct
13 Correct 274 ms 269688 KB Output is correct
14 Correct 403 ms 269564 KB Output is correct
15 Correct 323 ms 269616 KB Output is correct
16 Correct 274 ms 269688 KB Output is correct
17 Correct 274 ms 269564 KB Output is correct
18 Correct 277 ms 269688 KB Output is correct
19 Correct 302 ms 269716 KB Output is correct
20 Correct 291 ms 269560 KB Output is correct
21 Correct 284 ms 269688 KB Output is correct
22 Correct 319 ms 269664 KB Output is correct
23 Correct 285 ms 269700 KB Output is correct
24 Correct 314 ms 269688 KB Output is correct
25 Correct 280 ms 269688 KB Output is correct
26 Correct 294 ms 269668 KB Output is correct
27 Correct 305 ms 269720 KB Output is correct
28 Correct 286 ms 269672 KB Output is correct
29 Correct 344 ms 269688 KB Output is correct
30 Correct 298 ms 269744 KB Output is correct
31 Correct 285 ms 269608 KB Output is correct
32 Correct 336 ms 269604 KB Output is correct
33 Correct 281 ms 269688 KB Output is correct
34 Correct 275 ms 269604 KB Output is correct
35 Correct 276 ms 269688 KB Output is correct
36 Correct 308 ms 269816 KB Output is correct
37 Correct 278 ms 269716 KB Output is correct
38 Correct 275 ms 269660 KB Output is correct
39 Correct 276 ms 269720 KB Output is correct
40 Correct 277 ms 269688 KB Output is correct
41 Correct 288 ms 269672 KB Output is correct
42 Correct 304 ms 269844 KB Output is correct
43 Correct 302 ms 269704 KB Output is correct
44 Correct 279 ms 269692 KB Output is correct
45 Correct 279 ms 269652 KB Output is correct
46 Correct 279 ms 269688 KB Output is correct
47 Correct 280 ms 269688 KB Output is correct
48 Correct 279 ms 269688 KB Output is correct
49 Correct 275 ms 269688 KB Output is correct
50 Correct 304 ms 269832 KB Output is correct
51 Correct 304 ms 269816 KB Output is correct
52 Correct 277 ms 269688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 299 ms 269676 KB Output is correct
2 Correct 281 ms 269684 KB Output is correct
3 Correct 301 ms 269692 KB Output is correct
4 Correct 283 ms 269788 KB Output is correct
5 Correct 335 ms 269692 KB Output is correct
6 Correct 293 ms 269712 KB Output is correct
7 Correct 277 ms 269684 KB Output is correct
8 Correct 276 ms 269560 KB Output is correct
9 Correct 276 ms 269692 KB Output is correct
10 Correct 275 ms 269688 KB Output is correct
11 Correct 277 ms 269688 KB Output is correct
12 Correct 275 ms 269688 KB Output is correct
13 Correct 274 ms 269688 KB Output is correct
14 Correct 403 ms 269564 KB Output is correct
15 Correct 323 ms 269616 KB Output is correct
16 Correct 274 ms 269688 KB Output is correct
17 Correct 274 ms 269564 KB Output is correct
18 Correct 277 ms 269688 KB Output is correct
19 Correct 302 ms 269716 KB Output is correct
20 Correct 291 ms 269560 KB Output is correct
21 Correct 284 ms 269688 KB Output is correct
22 Correct 319 ms 269664 KB Output is correct
23 Correct 285 ms 269700 KB Output is correct
24 Correct 314 ms 269688 KB Output is correct
25 Correct 280 ms 269688 KB Output is correct
26 Correct 294 ms 269668 KB Output is correct
27 Correct 305 ms 269720 KB Output is correct
28 Correct 286 ms 269672 KB Output is correct
29 Correct 344 ms 269688 KB Output is correct
30 Correct 298 ms 269744 KB Output is correct
31 Correct 285 ms 269608 KB Output is correct
32 Correct 336 ms 269604 KB Output is correct
33 Correct 281 ms 269688 KB Output is correct
34 Correct 275 ms 269604 KB Output is correct
35 Correct 276 ms 269688 KB Output is correct
36 Correct 308 ms 269816 KB Output is correct
37 Correct 327 ms 269604 KB Output is correct
38 Correct 342 ms 269724 KB Output is correct
39 Correct 328 ms 269592 KB Output is correct
40 Correct 278 ms 269660 KB Output is correct
41 Correct 278 ms 269688 KB Output is correct
42 Correct 289 ms 269612 KB Output is correct
43 Correct 278 ms 269644 KB Output is correct
44 Correct 279 ms 269592 KB Output is correct
45 Correct 278 ms 269688 KB Output is correct
46 Correct 279 ms 269628 KB Output is correct
47 Correct 275 ms 269608 KB Output is correct
48 Correct 278 ms 269560 KB Output is correct
49 Correct 276 ms 269600 KB Output is correct
50 Correct 277 ms 269760 KB Output is correct
51 Correct 276 ms 269604 KB Output is correct
52 Correct 299 ms 269776 KB Output is correct
53 Correct 301 ms 269660 KB Output is correct
54 Correct 305 ms 270192 KB Output is correct
55 Correct 306 ms 270104 KB Output is correct
56 Correct 348 ms 275064 KB Output is correct
57 Correct 334 ms 275064 KB Output is correct
58 Correct 335 ms 275064 KB Output is correct
59 Correct 333 ms 274448 KB Output is correct
60 Correct 328 ms 275064 KB Output is correct
61 Correct 330 ms 274936 KB Output is correct
62 Correct 346 ms 274552 KB Output is correct
63 Correct 333 ms 274592 KB Output is correct
64 Correct 358 ms 274544 KB Output is correct
65 Correct 338 ms 275096 KB Output is correct
66 Correct 335 ms 274524 KB Output is correct
67 Correct 394 ms 274296 KB Output is correct
68 Correct 386 ms 274552 KB Output is correct
69 Correct 274 ms 269624 KB Output is correct
70 Correct 275 ms 269560 KB Output is correct
71 Correct 324 ms 274552 KB Output is correct
72 Correct 328 ms 274680 KB Output is correct
73 Correct 353 ms 274524 KB Output is correct
74 Correct 280 ms 269752 KB Output is correct
75 Correct 279 ms 269592 KB Output is correct
76 Correct 277 ms 269636 KB Output is correct
77 Correct 278 ms 269688 KB Output is correct
78 Correct 366 ms 273748 KB Output is correct
79 Correct 333 ms 273796 KB Output is correct
80 Correct 366 ms 273656 KB Output is correct
81 Correct 335 ms 274552 KB Output is correct
82 Correct 402 ms 273912 KB Output is correct
83 Correct 346 ms 273784 KB Output is correct
84 Correct 278 ms 269716 KB Output is correct
85 Correct 275 ms 269660 KB Output is correct
86 Correct 276 ms 269720 KB Output is correct
87 Correct 277 ms 269688 KB Output is correct
88 Correct 288 ms 269672 KB Output is correct
89 Correct 304 ms 269844 KB Output is correct
90 Correct 302 ms 269704 KB Output is correct
91 Correct 279 ms 269692 KB Output is correct
92 Correct 279 ms 269652 KB Output is correct
93 Correct 279 ms 269688 KB Output is correct
94 Correct 280 ms 269688 KB Output is correct
95 Correct 279 ms 269688 KB Output is correct
96 Correct 275 ms 269688 KB Output is correct
97 Correct 304 ms 269832 KB Output is correct
98 Correct 304 ms 269816 KB Output is correct
99 Correct 277 ms 269688 KB Output is correct
100 Correct 282 ms 269656 KB Output is correct
101 Correct 286 ms 270100 KB Output is correct
102 Correct 286 ms 270072 KB Output is correct
103 Correct 379 ms 274232 KB Output is correct
104 Correct 373 ms 274168 KB Output is correct
105 Correct 372 ms 274272 KB Output is correct
106 Correct 374 ms 273696 KB Output is correct
107 Correct 339 ms 274296 KB Output is correct
108 Correct 344 ms 274244 KB Output is correct
109 Correct 331 ms 274560 KB Output is correct
110 Correct 334 ms 274680 KB Output is correct
111 Correct 382 ms 273656 KB Output is correct
112 Correct 367 ms 274384 KB Output is correct
113 Correct 340 ms 273656 KB Output is correct
114 Correct 363 ms 273760 KB Output is correct
115 Correct 360 ms 273656 KB Output is correct