Submission #306405

# Submission time Handle Problem Language Result Execution time Memory
306405 2020-09-25T12:43:12 Z amunduzbaev Arranging Shoes (IOI19_shoes) C++14
100 / 100
184 ms 28536 KB
#include "shoes.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
long long res[200010];
long long vis[200011], dp[200010];
vector <long long> a1[100002], b[100002];
const long long maxn=2e5+7;
 
vector<long long> a;
vector<long long> t(4*maxn);
vector<long long> add(4*maxn,0);
 
void push(long long v)
{
    if(add[v])
    {
        add[v*2]+=add[v];
        add[v*2+1]+=add[v];
        add[v]=0;
    }
}
void build(long long v,long long tl,long long tr)
{
    if(tl==tr)
    {
        t[v]=a[tl];
    }
    else
    {
        long long tm=(tl+tr)/2;
        build(v*2,tl,tm);
        build(v*2+1,tm+1,tr);
    }
}
 
long long get(long long v,long long tl,long long tr,long long pos)
{
    if(tl==tr)
    {
        t[v]+=add[v];
        add[v]=0;
        return t[v];
    }
    else
    {
        long long tm=(tl+tr)/2;
        push(v);
        if(pos<=tm)
        {
            return get(v*2,tl,tm,pos);
        }
        else
        {
            return get(v*2+1,tm+1,tr,pos);
        }
    }
}
 
void Add(long long v,long long tl,long long tr,long long l,long long r,long long val)
{
    if(l>r)
    {
        return;
    }
    if(tl==l && tr==r)
    {
        add[v]+=val;
        return;
    }
    else
    {
        long long tm=(tl+tr)/2;
        Add(v*2,tl,tm,l,min(r,tm),val);
        Add(v*2+1,tm+1,tr,max(tm+1,l),r,val);
    }
}
long long count_swaps(std::vector<int> s) {
 
 
    long long sum = 0;
    for(long long i = 0 ; i < s.size(); i++){
        if(s[i]>0)
            a1[s[i]].push_back(i);
        else
            b[abs(s[i])].push_back(i);
    }
    for(long long i = 0 ; i <100001;i++){
        for(long long j = 0 ; j < a1[i].size();j++){
            dp[a1[i][j]]=b[i][j];
            dp[b[i][j]]=a1[i][j];
        }
    }
    long long n = s.size()+1;
    for(long long i = 0 ; i < s.size(); i++){
 
        if(vis[i]==1)
            continue;
        long long j=i+1;
 
 
        sum += dp[i] - i - 1 + get(1,0,n-1,dp[i]) - get(1,0,n-1,i);
        Add(1,0,n,i,dp[i],1);
 
        if(s[i] > 0)
            sum++;
        vis[dp[i]]=1;
    }
 
 
	return sum;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:82:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(long long i = 0 ; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
shoes.cpp:89:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(long long j = 0 ; j < a1[i].size();j++){
      |                               ~~^~~~~~~~~~~~~~
shoes.cpp:95:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(long long i = 0 ; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
shoes.cpp:99:19: warning: unused variable 'j' [-Wunused-variable]
   99 |         long long j=i+1;
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 12 ms 17536 KB Output is correct
2 Correct 11 ms 17536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 17536 KB Output is correct
2 Correct 11 ms 17536 KB Output is correct
3 Correct 12 ms 17536 KB Output is correct
4 Correct 11 ms 17536 KB Output is correct
5 Correct 11 ms 17536 KB Output is correct
6 Correct 12 ms 17536 KB Output is correct
7 Correct 11 ms 17536 KB Output is correct
8 Correct 11 ms 17536 KB Output is correct
9 Correct 11 ms 17536 KB Output is correct
10 Correct 11 ms 17664 KB Output is correct
11 Correct 11 ms 17536 KB Output is correct
12 Correct 11 ms 17536 KB Output is correct
13 Correct 11 ms 17536 KB Output is correct
14 Correct 11 ms 17536 KB Output is correct
15 Correct 11 ms 17536 KB Output is correct
16 Correct 11 ms 17536 KB Output is correct
17 Correct 11 ms 17536 KB Output is correct
18 Correct 11 ms 17536 KB Output is correct
19 Correct 11 ms 17536 KB Output is correct
20 Correct 11 ms 17536 KB Output is correct
21 Correct 10 ms 17536 KB Output is correct
22 Correct 11 ms 17536 KB Output is correct
23 Correct 11 ms 17536 KB Output is correct
24 Correct 11 ms 17536 KB Output is correct
25 Correct 11 ms 17536 KB Output is correct
26 Correct 11 ms 17536 KB Output is correct
27 Correct 11 ms 17536 KB Output is correct
28 Correct 11 ms 17536 KB Output is correct
29 Correct 11 ms 17536 KB Output is correct
30 Correct 11 ms 17536 KB Output is correct
31 Correct 10 ms 17536 KB Output is correct
32 Correct 11 ms 17536 KB Output is correct
33 Correct 12 ms 17536 KB Output is correct
34 Correct 10 ms 17536 KB Output is correct
35 Correct 10 ms 17536 KB Output is correct
36 Correct 10 ms 17536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 17536 KB Output is correct
2 Correct 11 ms 17536 KB Output is correct
3 Correct 11 ms 17536 KB Output is correct
4 Correct 11 ms 17536 KB Output is correct
5 Correct 11 ms 17536 KB Output is correct
6 Correct 11 ms 17536 KB Output is correct
7 Correct 11 ms 17536 KB Output is correct
8 Correct 11 ms 17536 KB Output is correct
9 Correct 11 ms 17536 KB Output is correct
10 Correct 11 ms 17536 KB Output is correct
11 Correct 11 ms 17536 KB Output is correct
12 Correct 11 ms 17536 KB Output is correct
13 Correct 11 ms 17536 KB Output is correct
14 Correct 11 ms 17536 KB Output is correct
15 Correct 11 ms 17536 KB Output is correct
16 Correct 11 ms 17536 KB Output is correct
17 Correct 11 ms 17536 KB Output is correct
18 Correct 12 ms 17664 KB Output is correct
19 Correct 12 ms 17664 KB Output is correct
20 Correct 18 ms 18304 KB Output is correct
21 Correct 18 ms 18376 KB Output is correct
22 Correct 89 ms 24036 KB Output is correct
23 Correct 81 ms 24036 KB Output is correct
24 Correct 85 ms 24072 KB Output is correct
25 Correct 88 ms 23152 KB Output is correct
26 Correct 89 ms 24036 KB Output is correct
27 Correct 76 ms 24036 KB Output is correct
28 Correct 91 ms 23148 KB Output is correct
29 Correct 91 ms 23144 KB Output is correct
30 Correct 89 ms 23148 KB Output is correct
31 Correct 88 ms 23928 KB Output is correct
32 Correct 89 ms 23144 KB Output is correct
33 Correct 86 ms 23148 KB Output is correct
34 Correct 90 ms 23216 KB Output is correct
35 Correct 11 ms 17536 KB Output is correct
36 Correct 11 ms 17536 KB Output is correct
37 Correct 90 ms 23148 KB Output is correct
38 Correct 92 ms 23148 KB Output is correct
39 Correct 93 ms 23148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 17536 KB Output is correct
2 Correct 11 ms 17536 KB Output is correct
3 Correct 11 ms 17536 KB Output is correct
4 Correct 11 ms 17536 KB Output is correct
5 Correct 135 ms 27772 KB Output is correct
6 Correct 108 ms 24056 KB Output is correct
7 Correct 127 ms 27768 KB Output is correct
8 Correct 89 ms 23728 KB Output is correct
9 Correct 133 ms 27768 KB Output is correct
10 Correct 117 ms 25208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 17536 KB Output is correct
2 Correct 11 ms 17536 KB Output is correct
3 Correct 12 ms 17536 KB Output is correct
4 Correct 11 ms 17536 KB Output is correct
5 Correct 11 ms 17536 KB Output is correct
6 Correct 12 ms 17536 KB Output is correct
7 Correct 11 ms 17536 KB Output is correct
8 Correct 11 ms 17536 KB Output is correct
9 Correct 11 ms 17536 KB Output is correct
10 Correct 11 ms 17664 KB Output is correct
11 Correct 11 ms 17536 KB Output is correct
12 Correct 11 ms 17536 KB Output is correct
13 Correct 11 ms 17536 KB Output is correct
14 Correct 11 ms 17536 KB Output is correct
15 Correct 11 ms 17536 KB Output is correct
16 Correct 11 ms 17536 KB Output is correct
17 Correct 11 ms 17536 KB Output is correct
18 Correct 11 ms 17536 KB Output is correct
19 Correct 11 ms 17536 KB Output is correct
20 Correct 11 ms 17536 KB Output is correct
21 Correct 10 ms 17536 KB Output is correct
22 Correct 11 ms 17536 KB Output is correct
23 Correct 11 ms 17536 KB Output is correct
24 Correct 11 ms 17536 KB Output is correct
25 Correct 11 ms 17536 KB Output is correct
26 Correct 11 ms 17536 KB Output is correct
27 Correct 11 ms 17536 KB Output is correct
28 Correct 11 ms 17536 KB Output is correct
29 Correct 11 ms 17536 KB Output is correct
30 Correct 11 ms 17536 KB Output is correct
31 Correct 10 ms 17536 KB Output is correct
32 Correct 11 ms 17536 KB Output is correct
33 Correct 12 ms 17536 KB Output is correct
34 Correct 10 ms 17536 KB Output is correct
35 Correct 10 ms 17536 KB Output is correct
36 Correct 10 ms 17536 KB Output is correct
37 Correct 11 ms 17536 KB Output is correct
38 Correct 11 ms 17536 KB Output is correct
39 Correct 11 ms 17536 KB Output is correct
40 Correct 11 ms 17536 KB Output is correct
41 Correct 14 ms 17664 KB Output is correct
42 Correct 12 ms 17664 KB Output is correct
43 Correct 12 ms 17664 KB Output is correct
44 Correct 12 ms 17664 KB Output is correct
45 Correct 11 ms 17664 KB Output is correct
46 Correct 12 ms 17664 KB Output is correct
47 Correct 12 ms 17608 KB Output is correct
48 Correct 11 ms 17664 KB Output is correct
49 Correct 11 ms 17664 KB Output is correct
50 Correct 11 ms 17664 KB Output is correct
51 Correct 11 ms 17664 KB Output is correct
52 Correct 11 ms 17664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 17536 KB Output is correct
2 Correct 11 ms 17536 KB Output is correct
3 Correct 12 ms 17536 KB Output is correct
4 Correct 11 ms 17536 KB Output is correct
5 Correct 11 ms 17536 KB Output is correct
6 Correct 12 ms 17536 KB Output is correct
7 Correct 11 ms 17536 KB Output is correct
8 Correct 11 ms 17536 KB Output is correct
9 Correct 11 ms 17536 KB Output is correct
10 Correct 11 ms 17664 KB Output is correct
11 Correct 11 ms 17536 KB Output is correct
12 Correct 11 ms 17536 KB Output is correct
13 Correct 11 ms 17536 KB Output is correct
14 Correct 11 ms 17536 KB Output is correct
15 Correct 11 ms 17536 KB Output is correct
16 Correct 11 ms 17536 KB Output is correct
17 Correct 11 ms 17536 KB Output is correct
18 Correct 11 ms 17536 KB Output is correct
19 Correct 11 ms 17536 KB Output is correct
20 Correct 11 ms 17536 KB Output is correct
21 Correct 10 ms 17536 KB Output is correct
22 Correct 11 ms 17536 KB Output is correct
23 Correct 11 ms 17536 KB Output is correct
24 Correct 11 ms 17536 KB Output is correct
25 Correct 11 ms 17536 KB Output is correct
26 Correct 11 ms 17536 KB Output is correct
27 Correct 11 ms 17536 KB Output is correct
28 Correct 11 ms 17536 KB Output is correct
29 Correct 11 ms 17536 KB Output is correct
30 Correct 11 ms 17536 KB Output is correct
31 Correct 10 ms 17536 KB Output is correct
32 Correct 11 ms 17536 KB Output is correct
33 Correct 12 ms 17536 KB Output is correct
34 Correct 10 ms 17536 KB Output is correct
35 Correct 10 ms 17536 KB Output is correct
36 Correct 10 ms 17536 KB Output is correct
37 Correct 11 ms 17536 KB Output is correct
38 Correct 11 ms 17536 KB Output is correct
39 Correct 11 ms 17536 KB Output is correct
40 Correct 11 ms 17536 KB Output is correct
41 Correct 11 ms 17536 KB Output is correct
42 Correct 11 ms 17536 KB Output is correct
43 Correct 11 ms 17536 KB Output is correct
44 Correct 11 ms 17536 KB Output is correct
45 Correct 11 ms 17536 KB Output is correct
46 Correct 11 ms 17536 KB Output is correct
47 Correct 11 ms 17536 KB Output is correct
48 Correct 11 ms 17536 KB Output is correct
49 Correct 11 ms 17536 KB Output is correct
50 Correct 11 ms 17536 KB Output is correct
51 Correct 11 ms 17536 KB Output is correct
52 Correct 12 ms 17664 KB Output is correct
53 Correct 12 ms 17664 KB Output is correct
54 Correct 18 ms 18304 KB Output is correct
55 Correct 18 ms 18376 KB Output is correct
56 Correct 89 ms 24036 KB Output is correct
57 Correct 81 ms 24036 KB Output is correct
58 Correct 85 ms 24072 KB Output is correct
59 Correct 88 ms 23152 KB Output is correct
60 Correct 89 ms 24036 KB Output is correct
61 Correct 76 ms 24036 KB Output is correct
62 Correct 91 ms 23148 KB Output is correct
63 Correct 91 ms 23144 KB Output is correct
64 Correct 89 ms 23148 KB Output is correct
65 Correct 88 ms 23928 KB Output is correct
66 Correct 89 ms 23144 KB Output is correct
67 Correct 86 ms 23148 KB Output is correct
68 Correct 90 ms 23216 KB Output is correct
69 Correct 11 ms 17536 KB Output is correct
70 Correct 11 ms 17536 KB Output is correct
71 Correct 90 ms 23148 KB Output is correct
72 Correct 92 ms 23148 KB Output is correct
73 Correct 93 ms 23148 KB Output is correct
74 Correct 11 ms 17536 KB Output is correct
75 Correct 11 ms 17536 KB Output is correct
76 Correct 11 ms 17536 KB Output is correct
77 Correct 11 ms 17536 KB Output is correct
78 Correct 135 ms 27772 KB Output is correct
79 Correct 108 ms 24056 KB Output is correct
80 Correct 127 ms 27768 KB Output is correct
81 Correct 89 ms 23728 KB Output is correct
82 Correct 133 ms 27768 KB Output is correct
83 Correct 117 ms 25208 KB Output is correct
84 Correct 11 ms 17536 KB Output is correct
85 Correct 11 ms 17536 KB Output is correct
86 Correct 11 ms 17536 KB Output is correct
87 Correct 11 ms 17536 KB Output is correct
88 Correct 14 ms 17664 KB Output is correct
89 Correct 12 ms 17664 KB Output is correct
90 Correct 12 ms 17664 KB Output is correct
91 Correct 12 ms 17664 KB Output is correct
92 Correct 11 ms 17664 KB Output is correct
93 Correct 12 ms 17664 KB Output is correct
94 Correct 12 ms 17608 KB Output is correct
95 Correct 11 ms 17664 KB Output is correct
96 Correct 11 ms 17664 KB Output is correct
97 Correct 11 ms 17664 KB Output is correct
98 Correct 11 ms 17664 KB Output is correct
99 Correct 11 ms 17664 KB Output is correct
100 Correct 12 ms 17664 KB Output is correct
101 Correct 22 ms 18560 KB Output is correct
102 Correct 22 ms 18304 KB Output is correct
103 Correct 184 ms 28536 KB Output is correct
104 Correct 136 ms 28536 KB Output is correct
105 Correct 156 ms 26104 KB Output is correct
106 Correct 133 ms 27768 KB Output is correct
107 Correct 117 ms 24952 KB Output is correct
108 Correct 107 ms 25336 KB Output is correct
109 Correct 92 ms 23916 KB Output is correct
110 Correct 89 ms 23276 KB Output is correct
111 Correct 130 ms 26976 KB Output is correct
112 Correct 159 ms 27100 KB Output is correct
113 Correct 131 ms 24056 KB Output is correct
114 Correct 137 ms 27768 KB Output is correct
115 Correct 130 ms 27768 KB Output is correct