# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
408863 |
2021-05-19T18:17:41 Z |
cpp219 |
Sorting (IOI15_sorting) |
C++14 |
|
361 ms |
30052 KB |
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <sorting.h>
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e6 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<ll> v,pos;
vector<LL> oper,ans;
ll n,m,id1[N],a[N],b[N],id2[N];
bool chk(ll mid){
for (ll i = 0;i < n;i++) a[i] = b[i] = v[i]; ans.clear();
for (ll i = 0;i < mid;i++){
ll x = oper[i].fs,y = oper[i].sc;
swap(a[x],a[y]);
}
for (ll i = 0;i < n;i++) id1[a[i]] = i,id2[b[i]] = i;
ll j = 0;
for (ll i = 0;i < mid;i++){
ll x = oper[i].fs,y = oper[i].sc;
swap(id2[b[x]],id2[b[y]]);
swap(b[x],b[y]);
while (j < n&&a[j] == j) j++;
if (j == n) ans.push_back({0,0});
else{
ans.push_back({id2[j],id2[a[j]]});
swap(b[id2[j]],b[id2[a[j]]]);
swap(id2[j],id2[a[j]]);
id1[a[j]] = id1[j]; swap(a[j],a[id1[j]]);
id1[j] = j;
}
}
for (ll i = 0;i < n - 1;i++) if (a[i] > a[i + 1]) return 0;
return 1;
}
ll findSwapPairs(ll num,ll S[],ll M,ll X[],ll Y[],ll P[],ll Q[]){
n = num; m = M;
for (ll i = 0;i < n;i++) v.push_back(S[i]);
for (ll i = 0;i < M;i++) oper.push_back({X[i],Y[i]});
ll l,mid,h;
l = 0; h = m;
//chk(3); exit(0);
while(l <= h){
mid = (l + h)/2;
if (chk(mid)) h = mid - 1;
else l = mid + 1;
}
chk(l); //cout<<ans.size(); exit(0);
while(ans.size() < l) ans.push_back({0,0});
for (ll i = 0;i < ans.size();i++) P[i] = ans[i].fs,Q[i] = ans[i].sc;
return l;
}
Compilation message
sorting.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
sorting.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
sorting.cpp: In function 'bool chk(int)':
sorting.cpp:20:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
20 | for (ll i = 0;i < n;i++) a[i] = b[i] = v[i]; ans.clear();
| ^~~
sorting.cpp:20:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
20 | for (ll i = 0;i < n;i++) a[i] = b[i] = v[i]; ans.clear();
| ^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:58:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
58 | while(ans.size() < l) ans.push_back({0,0});
| ~~~~~~~~~~~^~~
sorting.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (ll i = 0;i < ans.size();i++) P[i] = ans[i].fs,Q[i] = ans[i].sc;
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
2 ms |
708 KB |
Output is correct |
23 |
Correct |
2 ms |
824 KB |
Output is correct |
24 |
Correct |
2 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
820 KB |
Output is correct |
26 |
Correct |
2 ms |
708 KB |
Output is correct |
27 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
564 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
3 ms |
568 KB |
Output is correct |
11 |
Correct |
3 ms |
572 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
3 ms |
588 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
564 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
3 ms |
568 KB |
Output is correct |
11 |
Correct |
3 ms |
572 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
3 ms |
588 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
249 ms |
27784 KB |
Output is correct |
16 |
Correct |
284 ms |
28088 KB |
Output is correct |
17 |
Correct |
349 ms |
29140 KB |
Output is correct |
18 |
Correct |
123 ms |
24672 KB |
Output is correct |
19 |
Correct |
233 ms |
27416 KB |
Output is correct |
20 |
Correct |
255 ms |
27960 KB |
Output is correct |
21 |
Correct |
258 ms |
28052 KB |
Output is correct |
22 |
Correct |
253 ms |
27804 KB |
Output is correct |
23 |
Correct |
266 ms |
29776 KB |
Output is correct |
24 |
Correct |
342 ms |
29604 KB |
Output is correct |
25 |
Correct |
341 ms |
29268 KB |
Output is correct |
26 |
Correct |
256 ms |
27984 KB |
Output is correct |
27 |
Correct |
225 ms |
27300 KB |
Output is correct |
28 |
Correct |
334 ms |
29348 KB |
Output is correct |
29 |
Correct |
314 ms |
28752 KB |
Output is correct |
30 |
Correct |
182 ms |
26692 KB |
Output is correct |
31 |
Correct |
321 ms |
29224 KB |
Output is correct |
32 |
Correct |
274 ms |
29232 KB |
Output is correct |
33 |
Correct |
342 ms |
29540 KB |
Output is correct |
34 |
Correct |
311 ms |
29388 KB |
Output is correct |
35 |
Correct |
241 ms |
27256 KB |
Output is correct |
36 |
Correct |
104 ms |
25768 KB |
Output is correct |
37 |
Correct |
361 ms |
30052 KB |
Output is correct |
38 |
Correct |
360 ms |
29164 KB |
Output is correct |
39 |
Correct |
347 ms |
29308 KB |
Output is correct |