Submission #157525

# Submission time Handle Problem Language Result Execution time Memory
157525 2019-10-12T07:22:48 Z tevdore Arranging Shoes (IOI19_shoes) C++14
50 / 100
598 ms 409164 KB
#include<bits/stdc++.h>
#define mid (L+R)/2
using namespace std;
int i,ans,k;
int f[300001],sg[2000001];
queue<int>q1[300001];
queue<int>q2[300001];
vector<int>s;
void upd(int u,int L,int R,int pos,int y){
	if(R < pos || L > pos)return;
	if(R == L){sg[u]=y;return;}
	else{
		upd(u*2,L,mid,pos,y);
		upd(u*2+1,mid+1,R,pos,y);
		sg[u]=sg[u*2]+sg[u*2+1];
	}
}
int get(int u,int L,int R,int a,int b){
	if(b < L || a > R)return 0;
	if(a <= L && b >= R)return sg[u];
	return(get(u*2,L,mid,a,b)+get(u*2+1,mid+1,R,a,b));
}
int count_swaps(std:: vector<int>s){
    int n=s.size();
    for(i=0;i<s.size();i++){
        f[i+1]=s[i];
    }
    for(i=1;i<=n;i++){
        upd(1,1,n,i,1);
    }
    for(i=1;i<=n;i++){
		if(f[i] < 0){
		    k=-(f[i]);
			if(q2[k].size() == 0){
				q1[k].push(i);
				continue;
			}
			ans+=get(1,1,n,q2[k].front(),i)-1;
			upd(1,1,n,q2[k].front(),2);
			upd(1,1,n,i,0);
			q2[k].pop();
		}
		if(f[i] > 0){
		    k=f[i];
			if(q1[k].size() == 0){
				q2[k].push(i);
				continue;
			}
			ans+=get(1,1,n,q1[k].front(),i)-2;
			upd(1,1,n,q1[k].front(),2);
			upd(1,1,n,i,0);
			q1[k].pop();
		}
	}
	return ans;
}

Compilation message

shoes.cpp: In function 'int count_swaps(std::vector<int>)':
shoes.cpp:25:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<s.size();i++){
             ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 415 ms 404316 KB Output is correct
2 Correct 424 ms 404396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 404316 KB Output is correct
2 Correct 424 ms 404396 KB Output is correct
3 Correct 417 ms 404256 KB Output is correct
4 Correct 448 ms 404304 KB Output is correct
5 Correct 420 ms 404272 KB Output is correct
6 Correct 494 ms 404376 KB Output is correct
7 Correct 416 ms 404344 KB Output is correct
8 Correct 415 ms 404344 KB Output is correct
9 Correct 414 ms 404216 KB Output is correct
10 Correct 507 ms 404344 KB Output is correct
11 Correct 475 ms 404216 KB Output is correct
12 Correct 423 ms 404176 KB Output is correct
13 Correct 424 ms 404216 KB Output is correct
14 Correct 420 ms 404344 KB Output is correct
15 Correct 423 ms 404396 KB Output is correct
16 Correct 421 ms 404296 KB Output is correct
17 Correct 419 ms 404216 KB Output is correct
18 Correct 414 ms 404204 KB Output is correct
19 Correct 498 ms 404288 KB Output is correct
20 Correct 457 ms 404444 KB Output is correct
21 Correct 424 ms 404392 KB Output is correct
22 Correct 424 ms 404216 KB Output is correct
23 Correct 478 ms 404220 KB Output is correct
24 Correct 530 ms 404276 KB Output is correct
25 Correct 423 ms 404232 KB Output is correct
26 Correct 417 ms 404216 KB Output is correct
27 Correct 421 ms 404212 KB Output is correct
28 Correct 444 ms 404216 KB Output is correct
29 Correct 437 ms 404328 KB Output is correct
30 Correct 418 ms 404368 KB Output is correct
31 Correct 420 ms 404216 KB Output is correct
32 Correct 431 ms 404268 KB Output is correct
33 Correct 423 ms 404216 KB Output is correct
34 Correct 454 ms 404364 KB Output is correct
35 Correct 417 ms 404220 KB Output is correct
36 Correct 421 ms 404304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 404316 KB Output is correct
2 Correct 424 ms 404396 KB Output is correct
3 Correct 420 ms 404228 KB Output is correct
4 Correct 421 ms 404176 KB Output is correct
5 Correct 417 ms 404316 KB Output is correct
6 Correct 443 ms 404276 KB Output is correct
7 Correct 418 ms 404216 KB Output is correct
8 Correct 417 ms 404344 KB Output is correct
9 Correct 421 ms 404344 KB Output is correct
10 Correct 419 ms 404216 KB Output is correct
11 Correct 471 ms 404284 KB Output is correct
12 Correct 456 ms 404232 KB Output is correct
13 Correct 422 ms 404344 KB Output is correct
14 Correct 418 ms 404324 KB Output is correct
15 Correct 420 ms 404216 KB Output is correct
16 Correct 459 ms 404316 KB Output is correct
17 Correct 445 ms 404320 KB Output is correct
18 Correct 462 ms 404368 KB Output is correct
19 Correct 466 ms 404448 KB Output is correct
20 Correct 481 ms 404640 KB Output is correct
21 Correct 452 ms 404908 KB Output is correct
22 Correct 588 ms 408652 KB Output is correct
23 Correct 586 ms 408852 KB Output is correct
24 Correct 578 ms 408712 KB Output is correct
25 Incorrect 598 ms 409164 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 420 ms 404292 KB Output is correct
2 Correct 440 ms 404328 KB Output is correct
3 Correct 417 ms 404188 KB Output is correct
4 Correct 420 ms 404332 KB Output is correct
5 Incorrect 595 ms 408612 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 415 ms 404316 KB Output is correct
2 Correct 424 ms 404396 KB Output is correct
3 Correct 417 ms 404256 KB Output is correct
4 Correct 448 ms 404304 KB Output is correct
5 Correct 420 ms 404272 KB Output is correct
6 Correct 494 ms 404376 KB Output is correct
7 Correct 416 ms 404344 KB Output is correct
8 Correct 415 ms 404344 KB Output is correct
9 Correct 414 ms 404216 KB Output is correct
10 Correct 507 ms 404344 KB Output is correct
11 Correct 475 ms 404216 KB Output is correct
12 Correct 423 ms 404176 KB Output is correct
13 Correct 424 ms 404216 KB Output is correct
14 Correct 420 ms 404344 KB Output is correct
15 Correct 423 ms 404396 KB Output is correct
16 Correct 421 ms 404296 KB Output is correct
17 Correct 419 ms 404216 KB Output is correct
18 Correct 414 ms 404204 KB Output is correct
19 Correct 498 ms 404288 KB Output is correct
20 Correct 457 ms 404444 KB Output is correct
21 Correct 424 ms 404392 KB Output is correct
22 Correct 424 ms 404216 KB Output is correct
23 Correct 478 ms 404220 KB Output is correct
24 Correct 530 ms 404276 KB Output is correct
25 Correct 423 ms 404232 KB Output is correct
26 Correct 417 ms 404216 KB Output is correct
27 Correct 421 ms 404212 KB Output is correct
28 Correct 444 ms 404216 KB Output is correct
29 Correct 437 ms 404328 KB Output is correct
30 Correct 418 ms 404368 KB Output is correct
31 Correct 420 ms 404216 KB Output is correct
32 Correct 431 ms 404268 KB Output is correct
33 Correct 423 ms 404216 KB Output is correct
34 Correct 454 ms 404364 KB Output is correct
35 Correct 417 ms 404220 KB Output is correct
36 Correct 421 ms 404304 KB Output is correct
37 Correct 421 ms 404200 KB Output is correct
38 Correct 423 ms 404312 KB Output is correct
39 Correct 422 ms 404268 KB Output is correct
40 Correct 443 ms 404248 KB Output is correct
41 Correct 435 ms 404364 KB Output is correct
42 Correct 451 ms 404320 KB Output is correct
43 Correct 422 ms 404216 KB Output is correct
44 Correct 422 ms 404344 KB Output is correct
45 Correct 422 ms 404216 KB Output is correct
46 Correct 423 ms 404344 KB Output is correct
47 Correct 427 ms 404436 KB Output is correct
48 Correct 423 ms 404216 KB Output is correct
49 Correct 421 ms 404300 KB Output is correct
50 Correct 476 ms 404344 KB Output is correct
51 Correct 442 ms 404320 KB Output is correct
52 Correct 425 ms 404284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 404316 KB Output is correct
2 Correct 424 ms 404396 KB Output is correct
3 Correct 417 ms 404256 KB Output is correct
4 Correct 448 ms 404304 KB Output is correct
5 Correct 420 ms 404272 KB Output is correct
6 Correct 494 ms 404376 KB Output is correct
7 Correct 416 ms 404344 KB Output is correct
8 Correct 415 ms 404344 KB Output is correct
9 Correct 414 ms 404216 KB Output is correct
10 Correct 507 ms 404344 KB Output is correct
11 Correct 475 ms 404216 KB Output is correct
12 Correct 423 ms 404176 KB Output is correct
13 Correct 424 ms 404216 KB Output is correct
14 Correct 420 ms 404344 KB Output is correct
15 Correct 423 ms 404396 KB Output is correct
16 Correct 421 ms 404296 KB Output is correct
17 Correct 419 ms 404216 KB Output is correct
18 Correct 414 ms 404204 KB Output is correct
19 Correct 498 ms 404288 KB Output is correct
20 Correct 457 ms 404444 KB Output is correct
21 Correct 424 ms 404392 KB Output is correct
22 Correct 424 ms 404216 KB Output is correct
23 Correct 478 ms 404220 KB Output is correct
24 Correct 530 ms 404276 KB Output is correct
25 Correct 423 ms 404232 KB Output is correct
26 Correct 417 ms 404216 KB Output is correct
27 Correct 421 ms 404212 KB Output is correct
28 Correct 444 ms 404216 KB Output is correct
29 Correct 437 ms 404328 KB Output is correct
30 Correct 418 ms 404368 KB Output is correct
31 Correct 420 ms 404216 KB Output is correct
32 Correct 431 ms 404268 KB Output is correct
33 Correct 423 ms 404216 KB Output is correct
34 Correct 454 ms 404364 KB Output is correct
35 Correct 417 ms 404220 KB Output is correct
36 Correct 421 ms 404304 KB Output is correct
37 Correct 420 ms 404228 KB Output is correct
38 Correct 421 ms 404176 KB Output is correct
39 Correct 417 ms 404316 KB Output is correct
40 Correct 443 ms 404276 KB Output is correct
41 Correct 418 ms 404216 KB Output is correct
42 Correct 417 ms 404344 KB Output is correct
43 Correct 421 ms 404344 KB Output is correct
44 Correct 419 ms 404216 KB Output is correct
45 Correct 471 ms 404284 KB Output is correct
46 Correct 456 ms 404232 KB Output is correct
47 Correct 422 ms 404344 KB Output is correct
48 Correct 418 ms 404324 KB Output is correct
49 Correct 420 ms 404216 KB Output is correct
50 Correct 459 ms 404316 KB Output is correct
51 Correct 445 ms 404320 KB Output is correct
52 Correct 462 ms 404368 KB Output is correct
53 Correct 466 ms 404448 KB Output is correct
54 Correct 481 ms 404640 KB Output is correct
55 Correct 452 ms 404908 KB Output is correct
56 Correct 588 ms 408652 KB Output is correct
57 Correct 586 ms 408852 KB Output is correct
58 Correct 578 ms 408712 KB Output is correct
59 Incorrect 598 ms 409164 KB Output isn't correct
60 Halted 0 ms 0 KB -