Submission #378995

# Submission time Handle Problem Language Result Execution time Memory
378995 2021-03-17T08:16:24 Z Thistle Arranging Shoes (IOI19_shoes) C++14
100 / 100
152 ms 75328 KB
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using H=pair<ll, ll>;
using vi=vector<ll>;
#define vec vector
#define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) rng((i),(0),(n))
#define fs first
#define sc second
#define all(a) (a).begin(),(a).end()
#define siz(a) ll((a).size())

class BIT{
	int n;
	vi dat;
public:
	BIT(int n):n(n){
		dat.assign(n+1,0);
	}
	void add(int t,ll x){
		t++;
		while(t<=n){
			dat[t]+=x;
			t+=t&-t;
		}
	}
	ll query(int x){
		x++;
		ll ret=0;
		while(x>0){
			ret+=dat[x];
			x-=x&-x;
		}
		return ret;
	}
	ll query(int l,int r){
		if(r<=l) return 0;
		return query(r-1)-query(l-1);
	}
};

long long count_swaps(std::vector<int> s) {
	int n=siz(s)/2;
	vi v(2*n);
	int tmp=0;
	vec<queue<H>>cnt(n+1);
	//moshi mada amatteiru nara
	//sokomade tobashimasu
	BIT bit(2*n);
	rep(i,2*n) bit.add(i,1);
	ll ans=0;
	rep(i,2*n){
		int t=abs(s[i]);
		int k=0;
		if(s[i]>0) k=1;
		if(cnt[t].empty()){
			cnt[t].push(H{i,k});
			continue;
		}
		if(cnt[t].front().sc==k){
			cnt[t].push(H{i,k});
		}
		else{
			int r=cnt[t].front().fs;
			cnt[t].pop();
			ans+=bit.query(r+1,i);
			bit.add(i,-1);
			bit.add(r,1);
			if(k==0) ans++;
		}
	}
	return ans;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:9:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
shoes.cpp:10:18: note: in expansion of macro 'rng'
   10 | #define rep(i,n) rng((i),(0),(n))
      |                  ^~~
shoes.cpp:53:2: note: in expansion of macro 'rep'
   53 |  rep(i,2*n) bit.add(i,1);
      |  ^~~
shoes.cpp:9:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
shoes.cpp:10:18: note: in expansion of macro 'rng'
   10 | #define rep(i,n) rng((i),(0),(n))
      |                  ^~~
shoes.cpp:55:2: note: in expansion of macro 'rep'
   55 |  rep(i,2*n){
      |  ^~~
shoes.cpp:48:6: warning: unused variable 'tmp' [-Wunused-variable]
   48 |  int tmp=0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 372 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 276 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 1004 KB Output is correct
19 Correct 1 ms 1004 KB Output is correct
20 Correct 9 ms 7660 KB Output is correct
21 Correct 9 ms 7660 KB Output is correct
22 Correct 86 ms 73580 KB Output is correct
23 Correct 89 ms 73580 KB Output is correct
24 Correct 128 ms 73580 KB Output is correct
25 Correct 100 ms 74992 KB Output is correct
26 Correct 89 ms 73600 KB Output is correct
27 Correct 82 ms 73456 KB Output is correct
28 Correct 111 ms 75244 KB Output is correct
29 Correct 92 ms 75244 KB Output is correct
30 Correct 107 ms 75244 KB Output is correct
31 Correct 100 ms 73580 KB Output is correct
32 Correct 99 ms 75204 KB Output is correct
33 Correct 97 ms 74988 KB Output is correct
34 Correct 116 ms 75244 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 512 KB Output is correct
37 Correct 93 ms 75244 KB Output is correct
38 Correct 122 ms 75244 KB Output is correct
39 Correct 110 ms 75248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 372 KB Output is correct
5 Correct 134 ms 73584 KB Output is correct
6 Correct 126 ms 73836 KB Output is correct
7 Correct 138 ms 73652 KB Output is correct
8 Correct 105 ms 75248 KB Output is correct
9 Correct 143 ms 73708 KB Output is correct
10 Correct 152 ms 73580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 372 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 276 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 388 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 1004 KB Output is correct
42 Correct 1 ms 1004 KB Output is correct
43 Correct 2 ms 1004 KB Output is correct
44 Correct 2 ms 1004 KB Output is correct
45 Correct 2 ms 1024 KB Output is correct
46 Correct 2 ms 1004 KB Output is correct
47 Correct 2 ms 1004 KB Output is correct
48 Correct 2 ms 1004 KB Output is correct
49 Correct 2 ms 1004 KB Output is correct
50 Correct 2 ms 1004 KB Output is correct
51 Correct 1 ms 1004 KB Output is correct
52 Correct 2 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 372 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 276 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 512 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 492 KB Output is correct
52 Correct 1 ms 1004 KB Output is correct
53 Correct 1 ms 1004 KB Output is correct
54 Correct 9 ms 7660 KB Output is correct
55 Correct 9 ms 7660 KB Output is correct
56 Correct 86 ms 73580 KB Output is correct
57 Correct 89 ms 73580 KB Output is correct
58 Correct 128 ms 73580 KB Output is correct
59 Correct 100 ms 74992 KB Output is correct
60 Correct 89 ms 73600 KB Output is correct
61 Correct 82 ms 73456 KB Output is correct
62 Correct 111 ms 75244 KB Output is correct
63 Correct 92 ms 75244 KB Output is correct
64 Correct 107 ms 75244 KB Output is correct
65 Correct 100 ms 73580 KB Output is correct
66 Correct 99 ms 75204 KB Output is correct
67 Correct 97 ms 74988 KB Output is correct
68 Correct 116 ms 75244 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 512 KB Output is correct
71 Correct 93 ms 75244 KB Output is correct
72 Correct 122 ms 75244 KB Output is correct
73 Correct 110 ms 75248 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 372 KB Output is correct
78 Correct 134 ms 73584 KB Output is correct
79 Correct 126 ms 73836 KB Output is correct
80 Correct 138 ms 73652 KB Output is correct
81 Correct 105 ms 75248 KB Output is correct
82 Correct 143 ms 73708 KB Output is correct
83 Correct 152 ms 73580 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 1 ms 388 KB Output is correct
86 Correct 1 ms 364 KB Output is correct
87 Correct 1 ms 492 KB Output is correct
88 Correct 1 ms 1004 KB Output is correct
89 Correct 1 ms 1004 KB Output is correct
90 Correct 2 ms 1004 KB Output is correct
91 Correct 2 ms 1004 KB Output is correct
92 Correct 2 ms 1024 KB Output is correct
93 Correct 2 ms 1004 KB Output is correct
94 Correct 2 ms 1004 KB Output is correct
95 Correct 2 ms 1004 KB Output is correct
96 Correct 2 ms 1004 KB Output is correct
97 Correct 2 ms 1004 KB Output is correct
98 Correct 1 ms 1004 KB Output is correct
99 Correct 2 ms 1004 KB Output is correct
100 Correct 2 ms 1004 KB Output is correct
101 Correct 12 ms 7660 KB Output is correct
102 Correct 11 ms 7788 KB Output is correct
103 Correct 141 ms 73520 KB Output is correct
104 Correct 123 ms 73692 KB Output is correct
105 Correct 114 ms 73632 KB Output is correct
106 Correct 125 ms 73676 KB Output is correct
107 Correct 111 ms 73584 KB Output is correct
108 Correct 113 ms 73580 KB Output is correct
109 Correct 105 ms 75328 KB Output is correct
110 Correct 91 ms 75188 KB Output is correct
111 Correct 121 ms 73580 KB Output is correct
112 Correct 135 ms 73580 KB Output is correct
113 Correct 123 ms 73712 KB Output is correct
114 Correct 129 ms 73580 KB Output is correct
115 Correct 125 ms 73580 KB Output is correct