Submission #891431

# Submission time Handle Problem Language Result Execution time Memory
891431 2023-12-23T03:10:17 Z Sir_Ahmed_Imran Arranging Shoes (IOI19_shoes) C++17
100 / 100
216 ms 274704 KB
                              ///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long 
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define N 200000
int seg[4*N];
void add(int x,int v=1,int s=0,int e=N){
    seg[v]++;
    if(e-s==1) return;
    int mid=(s+e)/2;
    if(x<mid) add(x,2*v,s,mid);
    else add(x,2*v+1,mid,e);
}
int get(int l,int r,int v=1,int s=0,int e=N){
    if(r<=s || e<=l || r<=l) return 0;
    if(l<=s && e<=r) return seg[v];
    int mid=(s+e)/2;
    return get(l,r,2*v,s,mid)+get(l,r,2*v+1,mid,e);
}
queue<int> l[N];
queue<int> r[N];
ll count_swaps(vector<int> v){
    ll o=0;
    int n=v.size()/2;
    for(int i=0;i<2*n;i++){
        if(v[i]<0){
            if(r[-v[i]].empty()){
                add(i);
                l[-v[i]].push(i);
            }
            else{
                o+=get(r[-v[i]].front(),i);
                add(r[-v[i]].front());
                r[-v[i]].pop();
            }
        }
        else{
            if(l[v[i]].empty()){
                add(i);
                r[v[i]].push(i);
            }
            else{
                o+=get(l[v[i]].front(),i)-1;
                add(l[v[i]].front());
                l[v[i]].pop();
            }
        }
    }
    return o;
}
# Verdict Execution time Memory Grader output
1 Correct 150 ms 271396 KB Output is correct
2 Correct 124 ms 271188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 271396 KB Output is correct
2 Correct 124 ms 271188 KB Output is correct
3 Correct 125 ms 271232 KB Output is correct
4 Correct 126 ms 271340 KB Output is correct
5 Correct 123 ms 271184 KB Output is correct
6 Correct 120 ms 271200 KB Output is correct
7 Correct 120 ms 271188 KB Output is correct
8 Correct 127 ms 271184 KB Output is correct
9 Correct 125 ms 271188 KB Output is correct
10 Correct 123 ms 271348 KB Output is correct
11 Correct 123 ms 271188 KB Output is correct
12 Correct 128 ms 271140 KB Output is correct
13 Correct 119 ms 271292 KB Output is correct
14 Correct 121 ms 271188 KB Output is correct
15 Correct 119 ms 271184 KB Output is correct
16 Correct 123 ms 271444 KB Output is correct
17 Correct 118 ms 271188 KB Output is correct
18 Correct 121 ms 271184 KB Output is correct
19 Correct 121 ms 271144 KB Output is correct
20 Correct 122 ms 271180 KB Output is correct
21 Correct 121 ms 271388 KB Output is correct
22 Correct 120 ms 271136 KB Output is correct
23 Correct 120 ms 271192 KB Output is correct
24 Correct 120 ms 271304 KB Output is correct
25 Correct 122 ms 271188 KB Output is correct
26 Correct 120 ms 271184 KB Output is correct
27 Correct 131 ms 271320 KB Output is correct
28 Correct 122 ms 271188 KB Output is correct
29 Correct 122 ms 271172 KB Output is correct
30 Correct 122 ms 271184 KB Output is correct
31 Correct 123 ms 271304 KB Output is correct
32 Correct 125 ms 271356 KB Output is correct
33 Correct 124 ms 271188 KB Output is correct
34 Correct 123 ms 271224 KB Output is correct
35 Correct 119 ms 271148 KB Output is correct
36 Correct 122 ms 271184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 271396 KB Output is correct
2 Correct 124 ms 271188 KB Output is correct
3 Correct 122 ms 271188 KB Output is correct
4 Correct 121 ms 271292 KB Output is correct
5 Correct 121 ms 271188 KB Output is correct
6 Correct 120 ms 271188 KB Output is correct
7 Correct 123 ms 271292 KB Output is correct
8 Correct 124 ms 271188 KB Output is correct
9 Correct 135 ms 271168 KB Output is correct
10 Correct 120 ms 271184 KB Output is correct
11 Correct 119 ms 271188 KB Output is correct
12 Correct 119 ms 271188 KB Output is correct
13 Correct 125 ms 271408 KB Output is correct
14 Correct 130 ms 271188 KB Output is correct
15 Correct 120 ms 271188 KB Output is correct
16 Correct 123 ms 271184 KB Output is correct
17 Correct 121 ms 271232 KB Output is correct
18 Correct 120 ms 271176 KB Output is correct
19 Correct 120 ms 271268 KB Output is correct
20 Correct 126 ms 271444 KB Output is correct
21 Correct 126 ms 271376 KB Output is correct
22 Correct 163 ms 273232 KB Output is correct
23 Correct 158 ms 274516 KB Output is correct
24 Correct 173 ms 274496 KB Output is correct
25 Correct 171 ms 274260 KB Output is correct
26 Correct 163 ms 274516 KB Output is correct
27 Correct 156 ms 274276 KB Output is correct
28 Correct 171 ms 274652 KB Output is correct
29 Correct 171 ms 274512 KB Output is correct
30 Correct 171 ms 274512 KB Output is correct
31 Correct 166 ms 274616 KB Output is correct
32 Correct 179 ms 274436 KB Output is correct
33 Correct 174 ms 274428 KB Output is correct
34 Correct 172 ms 274704 KB Output is correct
35 Correct 123 ms 271372 KB Output is correct
36 Correct 125 ms 271188 KB Output is correct
37 Correct 174 ms 274516 KB Output is correct
38 Correct 175 ms 274512 KB Output is correct
39 Correct 179 ms 274512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 271636 KB Output is correct
2 Correct 123 ms 271256 KB Output is correct
3 Correct 119 ms 271248 KB Output is correct
4 Correct 119 ms 271188 KB Output is correct
5 Correct 199 ms 272720 KB Output is correct
6 Correct 175 ms 272944 KB Output is correct
7 Correct 196 ms 272804 KB Output is correct
8 Correct 175 ms 273236 KB Output is correct
9 Correct 202 ms 272728 KB Output is correct
10 Correct 185 ms 273220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 271396 KB Output is correct
2 Correct 124 ms 271188 KB Output is correct
3 Correct 125 ms 271232 KB Output is correct
4 Correct 126 ms 271340 KB Output is correct
5 Correct 123 ms 271184 KB Output is correct
6 Correct 120 ms 271200 KB Output is correct
7 Correct 120 ms 271188 KB Output is correct
8 Correct 127 ms 271184 KB Output is correct
9 Correct 125 ms 271188 KB Output is correct
10 Correct 123 ms 271348 KB Output is correct
11 Correct 123 ms 271188 KB Output is correct
12 Correct 128 ms 271140 KB Output is correct
13 Correct 119 ms 271292 KB Output is correct
14 Correct 121 ms 271188 KB Output is correct
15 Correct 119 ms 271184 KB Output is correct
16 Correct 123 ms 271444 KB Output is correct
17 Correct 118 ms 271188 KB Output is correct
18 Correct 121 ms 271184 KB Output is correct
19 Correct 121 ms 271144 KB Output is correct
20 Correct 122 ms 271180 KB Output is correct
21 Correct 121 ms 271388 KB Output is correct
22 Correct 120 ms 271136 KB Output is correct
23 Correct 120 ms 271192 KB Output is correct
24 Correct 120 ms 271304 KB Output is correct
25 Correct 122 ms 271188 KB Output is correct
26 Correct 120 ms 271184 KB Output is correct
27 Correct 131 ms 271320 KB Output is correct
28 Correct 122 ms 271188 KB Output is correct
29 Correct 122 ms 271172 KB Output is correct
30 Correct 122 ms 271184 KB Output is correct
31 Correct 123 ms 271304 KB Output is correct
32 Correct 125 ms 271356 KB Output is correct
33 Correct 124 ms 271188 KB Output is correct
34 Correct 123 ms 271224 KB Output is correct
35 Correct 119 ms 271148 KB Output is correct
36 Correct 122 ms 271184 KB Output is correct
37 Correct 121 ms 271188 KB Output is correct
38 Correct 123 ms 271552 KB Output is correct
39 Correct 123 ms 271180 KB Output is correct
40 Correct 120 ms 271188 KB Output is correct
41 Correct 120 ms 271300 KB Output is correct
42 Correct 127 ms 271300 KB Output is correct
43 Correct 121 ms 271188 KB Output is correct
44 Correct 123 ms 271372 KB Output is correct
45 Correct 125 ms 271188 KB Output is correct
46 Correct 130 ms 271520 KB Output is correct
47 Correct 122 ms 271284 KB Output is correct
48 Correct 120 ms 271184 KB Output is correct
49 Correct 123 ms 271368 KB Output is correct
50 Correct 123 ms 271152 KB Output is correct
51 Correct 120 ms 271252 KB Output is correct
52 Correct 121 ms 271188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 271396 KB Output is correct
2 Correct 124 ms 271188 KB Output is correct
3 Correct 125 ms 271232 KB Output is correct
4 Correct 126 ms 271340 KB Output is correct
5 Correct 123 ms 271184 KB Output is correct
6 Correct 120 ms 271200 KB Output is correct
7 Correct 120 ms 271188 KB Output is correct
8 Correct 127 ms 271184 KB Output is correct
9 Correct 125 ms 271188 KB Output is correct
10 Correct 123 ms 271348 KB Output is correct
11 Correct 123 ms 271188 KB Output is correct
12 Correct 128 ms 271140 KB Output is correct
13 Correct 119 ms 271292 KB Output is correct
14 Correct 121 ms 271188 KB Output is correct
15 Correct 119 ms 271184 KB Output is correct
16 Correct 123 ms 271444 KB Output is correct
17 Correct 118 ms 271188 KB Output is correct
18 Correct 121 ms 271184 KB Output is correct
19 Correct 121 ms 271144 KB Output is correct
20 Correct 122 ms 271180 KB Output is correct
21 Correct 121 ms 271388 KB Output is correct
22 Correct 120 ms 271136 KB Output is correct
23 Correct 120 ms 271192 KB Output is correct
24 Correct 120 ms 271304 KB Output is correct
25 Correct 122 ms 271188 KB Output is correct
26 Correct 120 ms 271184 KB Output is correct
27 Correct 131 ms 271320 KB Output is correct
28 Correct 122 ms 271188 KB Output is correct
29 Correct 122 ms 271172 KB Output is correct
30 Correct 122 ms 271184 KB Output is correct
31 Correct 123 ms 271304 KB Output is correct
32 Correct 125 ms 271356 KB Output is correct
33 Correct 124 ms 271188 KB Output is correct
34 Correct 123 ms 271224 KB Output is correct
35 Correct 119 ms 271148 KB Output is correct
36 Correct 122 ms 271184 KB Output is correct
37 Correct 122 ms 271188 KB Output is correct
38 Correct 121 ms 271292 KB Output is correct
39 Correct 121 ms 271188 KB Output is correct
40 Correct 120 ms 271188 KB Output is correct
41 Correct 123 ms 271292 KB Output is correct
42 Correct 124 ms 271188 KB Output is correct
43 Correct 135 ms 271168 KB Output is correct
44 Correct 120 ms 271184 KB Output is correct
45 Correct 119 ms 271188 KB Output is correct
46 Correct 119 ms 271188 KB Output is correct
47 Correct 125 ms 271408 KB Output is correct
48 Correct 130 ms 271188 KB Output is correct
49 Correct 120 ms 271188 KB Output is correct
50 Correct 123 ms 271184 KB Output is correct
51 Correct 121 ms 271232 KB Output is correct
52 Correct 120 ms 271176 KB Output is correct
53 Correct 120 ms 271268 KB Output is correct
54 Correct 126 ms 271444 KB Output is correct
55 Correct 126 ms 271376 KB Output is correct
56 Correct 163 ms 273232 KB Output is correct
57 Correct 158 ms 274516 KB Output is correct
58 Correct 173 ms 274496 KB Output is correct
59 Correct 171 ms 274260 KB Output is correct
60 Correct 163 ms 274516 KB Output is correct
61 Correct 156 ms 274276 KB Output is correct
62 Correct 171 ms 274652 KB Output is correct
63 Correct 171 ms 274512 KB Output is correct
64 Correct 171 ms 274512 KB Output is correct
65 Correct 166 ms 274616 KB Output is correct
66 Correct 179 ms 274436 KB Output is correct
67 Correct 174 ms 274428 KB Output is correct
68 Correct 172 ms 274704 KB Output is correct
69 Correct 123 ms 271372 KB Output is correct
70 Correct 125 ms 271188 KB Output is correct
71 Correct 174 ms 274516 KB Output is correct
72 Correct 175 ms 274512 KB Output is correct
73 Correct 179 ms 274512 KB Output is correct
74 Correct 124 ms 271636 KB Output is correct
75 Correct 123 ms 271256 KB Output is correct
76 Correct 119 ms 271248 KB Output is correct
77 Correct 119 ms 271188 KB Output is correct
78 Correct 199 ms 272720 KB Output is correct
79 Correct 175 ms 272944 KB Output is correct
80 Correct 196 ms 272804 KB Output is correct
81 Correct 175 ms 273236 KB Output is correct
82 Correct 202 ms 272728 KB Output is correct
83 Correct 185 ms 273220 KB Output is correct
84 Correct 121 ms 271188 KB Output is correct
85 Correct 123 ms 271552 KB Output is correct
86 Correct 123 ms 271180 KB Output is correct
87 Correct 120 ms 271188 KB Output is correct
88 Correct 120 ms 271300 KB Output is correct
89 Correct 127 ms 271300 KB Output is correct
90 Correct 121 ms 271188 KB Output is correct
91 Correct 123 ms 271372 KB Output is correct
92 Correct 125 ms 271188 KB Output is correct
93 Correct 130 ms 271520 KB Output is correct
94 Correct 122 ms 271284 KB Output is correct
95 Correct 120 ms 271184 KB Output is correct
96 Correct 123 ms 271368 KB Output is correct
97 Correct 123 ms 271152 KB Output is correct
98 Correct 120 ms 271252 KB Output is correct
99 Correct 121 ms 271188 KB Output is correct
100 Correct 123 ms 271436 KB Output is correct
101 Correct 128 ms 271440 KB Output is correct
102 Correct 126 ms 271512 KB Output is correct
103 Correct 216 ms 274488 KB Output is correct
104 Correct 184 ms 274476 KB Output is correct
105 Correct 189 ms 274516 KB Output is correct
106 Correct 197 ms 274024 KB Output is correct
107 Correct 170 ms 274516 KB Output is correct
108 Correct 169 ms 274456 KB Output is correct
109 Correct 171 ms 274452 KB Output is correct
110 Correct 173 ms 274672 KB Output is correct
111 Correct 193 ms 273952 KB Output is correct
112 Correct 204 ms 274512 KB Output is correct
113 Correct 186 ms 274356 KB Output is correct
114 Correct 191 ms 274216 KB Output is correct
115 Correct 194 ms 274256 KB Output is correct