Submission #255705

# Submission time Handle Problem Language Result Execution time Memory
255705 2020-08-01T15:44:19 Z Namnamseo Rope (JOI17_rope) C++17
80 / 100
2500 ms 75384 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back

int n, m;
int col[1000010];

int ans[1000010];

vector<int> adj[1000010];

const int M=1048576;

void upd(int p, int v, int *t){
	p+=M; t[p]+=v; p>>=1;
	while(p) t[p]=max(t[p*2], t[p*2+1]), p>>=1;
}

int rM(int l, int r, int *t){
	int ret=0;
	l+=M; r+=M;
	while(l<=r){
		if(l&1) ret=max(ret, t[l++]);
		if((r&1)==0) ret=max(ret, t[r--]);
		l>>=1; r>>=1;
	}
	return ret;
}

void Do(){
	for(auto& v:adj) v.clear();
	int *self = new int[1000010]();
	int *t = new int[M<<1]();
    
    for(int i=1; i<=n; i+=2){
		if(i+1 <= n){
			int a=col[i], b=col[i+1];
			if(a == b){
				++self[a];
				upd(a, 2, t);
				continue;
			}
			adj[a].pb(b); adj[b].pb(a);
			upd(a, 1, t); upd(b, 1, t);
		} else upd(col[i], 1, t);
    }
    
    for(int i=1; i<=m; ++i){
		for(int x:adj[i]) upd(x, -1, t);
		int jib=rM(i, i, t); upd(i, -jib, t);
		ans[i]=min(ans[i],
			n-rM(1, m, t)-jib
		);
		for(int x:adj[i]) upd(x, 1, t);
		upd(i, jib, t);
    }

    delete[] self;
    delete[] t;
}

void Do2(){
	for(auto& v:adj) v.clear();
	int *self = new int[1000010]();
	int *t = new int[M<<1]();
    
    upd(col[1], 1, t);
    for(int i=2; i<=n; i+=2){
		if(i+1 <= n){
			int a=col[i], b=col[i+1];
			if(a == b){
				++self[a];
				upd(a, 2, t);
				continue;
			}
			adj[a].pb(b); adj[b].pb(a);
			upd(a, 1, t); upd(b, 1, t);
		} else upd(col[i], 1, t);
    }
    
    for(int i=1; i<=m; ++i){
		for(int x:adj[i]) upd(x, -1, t);
		int jib=rM(i, i, t); upd(i, -jib, t);
		ans[i]=min(ans[i],
			n-rM(1, m, t)-jib
		);
		for(int x:adj[i]) upd(x, 1, t);
		upd(i, jib, t);
    }

    delete[] self;
    delete[] t;
}

int main()
{
    read(n, m);
    for(int i=1; i<=n; ++i) read(col[i]);
    fill(ans+1, ans+m+1, n+1);
    Do(); Do2();
    reverse(col+1, col+n+1);
    Do(); Do2();
    for(int i=1; i<=m; ++i) printf("%d\n", ans[i]);
    return 0;
}

Compilation message

rope.cpp: In function 'void read(int&)':
rope.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(int& x){ scanf("%d",&x); }
                    ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 42 ms 36016 KB Output is correct
2 Correct 46 ms 36020 KB Output is correct
3 Correct 45 ms 36016 KB Output is correct
4 Correct 43 ms 36024 KB Output is correct
5 Correct 44 ms 36016 KB Output is correct
6 Correct 45 ms 36016 KB Output is correct
7 Correct 50 ms 36016 KB Output is correct
8 Correct 44 ms 36016 KB Output is correct
9 Correct 42 ms 36016 KB Output is correct
10 Correct 43 ms 36024 KB Output is correct
11 Correct 42 ms 36024 KB Output is correct
12 Correct 43 ms 36016 KB Output is correct
13 Correct 42 ms 36016 KB Output is correct
14 Correct 44 ms 36016 KB Output is correct
15 Correct 43 ms 36016 KB Output is correct
16 Correct 43 ms 36096 KB Output is correct
17 Correct 42 ms 36016 KB Output is correct
18 Correct 43 ms 36016 KB Output is correct
19 Correct 42 ms 36024 KB Output is correct
20 Correct 44 ms 36016 KB Output is correct
21 Correct 43 ms 36016 KB Output is correct
22 Correct 43 ms 36016 KB Output is correct
23 Correct 42 ms 36016 KB Output is correct
24 Correct 43 ms 36016 KB Output is correct
25 Correct 42 ms 36016 KB Output is correct
26 Correct 44 ms 36020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 36016 KB Output is correct
2 Correct 46 ms 36020 KB Output is correct
3 Correct 45 ms 36016 KB Output is correct
4 Correct 43 ms 36024 KB Output is correct
5 Correct 44 ms 36016 KB Output is correct
6 Correct 45 ms 36016 KB Output is correct
7 Correct 50 ms 36016 KB Output is correct
8 Correct 44 ms 36016 KB Output is correct
9 Correct 42 ms 36016 KB Output is correct
10 Correct 43 ms 36024 KB Output is correct
11 Correct 42 ms 36024 KB Output is correct
12 Correct 43 ms 36016 KB Output is correct
13 Correct 42 ms 36016 KB Output is correct
14 Correct 44 ms 36016 KB Output is correct
15 Correct 43 ms 36016 KB Output is correct
16 Correct 43 ms 36096 KB Output is correct
17 Correct 42 ms 36016 KB Output is correct
18 Correct 43 ms 36016 KB Output is correct
19 Correct 42 ms 36024 KB Output is correct
20 Correct 44 ms 36016 KB Output is correct
21 Correct 43 ms 36016 KB Output is correct
22 Correct 43 ms 36016 KB Output is correct
23 Correct 42 ms 36016 KB Output is correct
24 Correct 43 ms 36016 KB Output is correct
25 Correct 42 ms 36016 KB Output is correct
26 Correct 44 ms 36020 KB Output is correct
27 Correct 174 ms 37260 KB Output is correct
28 Correct 163 ms 37148 KB Output is correct
29 Correct 182 ms 37168 KB Output is correct
30 Correct 178 ms 36984 KB Output is correct
31 Correct 185 ms 37260 KB Output is correct
32 Correct 162 ms 37112 KB Output is correct
33 Correct 177 ms 37168 KB Output is correct
34 Correct 170 ms 37004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 36016 KB Output is correct
2 Correct 46 ms 36020 KB Output is correct
3 Correct 45 ms 36016 KB Output is correct
4 Correct 43 ms 36024 KB Output is correct
5 Correct 44 ms 36016 KB Output is correct
6 Correct 45 ms 36016 KB Output is correct
7 Correct 50 ms 36016 KB Output is correct
8 Correct 44 ms 36016 KB Output is correct
9 Correct 42 ms 36016 KB Output is correct
10 Correct 43 ms 36024 KB Output is correct
11 Correct 42 ms 36024 KB Output is correct
12 Correct 43 ms 36016 KB Output is correct
13 Correct 42 ms 36016 KB Output is correct
14 Correct 44 ms 36016 KB Output is correct
15 Correct 43 ms 36016 KB Output is correct
16 Correct 43 ms 36096 KB Output is correct
17 Correct 42 ms 36016 KB Output is correct
18 Correct 43 ms 36016 KB Output is correct
19 Correct 42 ms 36024 KB Output is correct
20 Correct 44 ms 36016 KB Output is correct
21 Correct 43 ms 36016 KB Output is correct
22 Correct 43 ms 36016 KB Output is correct
23 Correct 42 ms 36016 KB Output is correct
24 Correct 43 ms 36016 KB Output is correct
25 Correct 42 ms 36016 KB Output is correct
26 Correct 44 ms 36020 KB Output is correct
27 Correct 174 ms 37260 KB Output is correct
28 Correct 163 ms 37148 KB Output is correct
29 Correct 182 ms 37168 KB Output is correct
30 Correct 178 ms 36984 KB Output is correct
31 Correct 185 ms 37260 KB Output is correct
32 Correct 162 ms 37112 KB Output is correct
33 Correct 177 ms 37168 KB Output is correct
34 Correct 170 ms 37004 KB Output is correct
35 Correct 127 ms 37168 KB Output is correct
36 Correct 129 ms 37260 KB Output is correct
37 Correct 122 ms 37296 KB Output is correct
38 Correct 126 ms 37264 KB Output is correct
39 Correct 130 ms 37188 KB Output is correct
40 Correct 127 ms 37296 KB Output is correct
41 Correct 129 ms 37280 KB Output is correct
42 Correct 137 ms 37256 KB Output is correct
43 Correct 136 ms 37296 KB Output is correct
44 Correct 131 ms 37260 KB Output is correct
45 Correct 127 ms 37240 KB Output is correct
46 Correct 127 ms 37240 KB Output is correct
47 Correct 135 ms 37388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 36016 KB Output is correct
2 Correct 46 ms 36020 KB Output is correct
3 Correct 45 ms 36016 KB Output is correct
4 Correct 43 ms 36024 KB Output is correct
5 Correct 44 ms 36016 KB Output is correct
6 Correct 45 ms 36016 KB Output is correct
7 Correct 50 ms 36016 KB Output is correct
8 Correct 44 ms 36016 KB Output is correct
9 Correct 42 ms 36016 KB Output is correct
10 Correct 43 ms 36024 KB Output is correct
11 Correct 42 ms 36024 KB Output is correct
12 Correct 43 ms 36016 KB Output is correct
13 Correct 42 ms 36016 KB Output is correct
14 Correct 44 ms 36016 KB Output is correct
15 Correct 43 ms 36016 KB Output is correct
16 Correct 43 ms 36096 KB Output is correct
17 Correct 42 ms 36016 KB Output is correct
18 Correct 43 ms 36016 KB Output is correct
19 Correct 42 ms 36024 KB Output is correct
20 Correct 44 ms 36016 KB Output is correct
21 Correct 43 ms 36016 KB Output is correct
22 Correct 43 ms 36016 KB Output is correct
23 Correct 42 ms 36016 KB Output is correct
24 Correct 43 ms 36016 KB Output is correct
25 Correct 42 ms 36016 KB Output is correct
26 Correct 44 ms 36020 KB Output is correct
27 Correct 174 ms 37260 KB Output is correct
28 Correct 163 ms 37148 KB Output is correct
29 Correct 182 ms 37168 KB Output is correct
30 Correct 178 ms 36984 KB Output is correct
31 Correct 185 ms 37260 KB Output is correct
32 Correct 162 ms 37112 KB Output is correct
33 Correct 177 ms 37168 KB Output is correct
34 Correct 170 ms 37004 KB Output is correct
35 Correct 127 ms 37168 KB Output is correct
36 Correct 129 ms 37260 KB Output is correct
37 Correct 122 ms 37296 KB Output is correct
38 Correct 126 ms 37264 KB Output is correct
39 Correct 130 ms 37188 KB Output is correct
40 Correct 127 ms 37296 KB Output is correct
41 Correct 129 ms 37280 KB Output is correct
42 Correct 137 ms 37256 KB Output is correct
43 Correct 136 ms 37296 KB Output is correct
44 Correct 131 ms 37260 KB Output is correct
45 Correct 127 ms 37240 KB Output is correct
46 Correct 127 ms 37240 KB Output is correct
47 Correct 135 ms 37388 KB Output is correct
48 Correct 886 ms 46860 KB Output is correct
49 Correct 871 ms 46840 KB Output is correct
50 Correct 862 ms 46844 KB Output is correct
51 Correct 857 ms 46840 KB Output is correct
52 Correct 851 ms 45836 KB Output is correct
53 Correct 844 ms 46092 KB Output is correct
54 Correct 832 ms 45068 KB Output is correct
55 Correct 825 ms 44940 KB Output is correct
56 Correct 852 ms 44464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 36016 KB Output is correct
2 Correct 46 ms 36020 KB Output is correct
3 Correct 45 ms 36016 KB Output is correct
4 Correct 43 ms 36024 KB Output is correct
5 Correct 44 ms 36016 KB Output is correct
6 Correct 45 ms 36016 KB Output is correct
7 Correct 50 ms 36016 KB Output is correct
8 Correct 44 ms 36016 KB Output is correct
9 Correct 42 ms 36016 KB Output is correct
10 Correct 43 ms 36024 KB Output is correct
11 Correct 42 ms 36024 KB Output is correct
12 Correct 43 ms 36016 KB Output is correct
13 Correct 42 ms 36016 KB Output is correct
14 Correct 44 ms 36016 KB Output is correct
15 Correct 43 ms 36016 KB Output is correct
16 Correct 43 ms 36096 KB Output is correct
17 Correct 42 ms 36016 KB Output is correct
18 Correct 43 ms 36016 KB Output is correct
19 Correct 42 ms 36024 KB Output is correct
20 Correct 44 ms 36016 KB Output is correct
21 Correct 43 ms 36016 KB Output is correct
22 Correct 43 ms 36016 KB Output is correct
23 Correct 42 ms 36016 KB Output is correct
24 Correct 43 ms 36016 KB Output is correct
25 Correct 42 ms 36016 KB Output is correct
26 Correct 44 ms 36020 KB Output is correct
27 Correct 174 ms 37260 KB Output is correct
28 Correct 163 ms 37148 KB Output is correct
29 Correct 182 ms 37168 KB Output is correct
30 Correct 178 ms 36984 KB Output is correct
31 Correct 185 ms 37260 KB Output is correct
32 Correct 162 ms 37112 KB Output is correct
33 Correct 177 ms 37168 KB Output is correct
34 Correct 170 ms 37004 KB Output is correct
35 Correct 127 ms 37168 KB Output is correct
36 Correct 129 ms 37260 KB Output is correct
37 Correct 122 ms 37296 KB Output is correct
38 Correct 126 ms 37264 KB Output is correct
39 Correct 130 ms 37188 KB Output is correct
40 Correct 127 ms 37296 KB Output is correct
41 Correct 129 ms 37280 KB Output is correct
42 Correct 137 ms 37256 KB Output is correct
43 Correct 136 ms 37296 KB Output is correct
44 Correct 131 ms 37260 KB Output is correct
45 Correct 127 ms 37240 KB Output is correct
46 Correct 127 ms 37240 KB Output is correct
47 Correct 135 ms 37388 KB Output is correct
48 Correct 886 ms 46860 KB Output is correct
49 Correct 871 ms 46840 KB Output is correct
50 Correct 862 ms 46844 KB Output is correct
51 Correct 857 ms 46840 KB Output is correct
52 Correct 851 ms 45836 KB Output is correct
53 Correct 844 ms 46092 KB Output is correct
54 Correct 832 ms 45068 KB Output is correct
55 Correct 825 ms 44940 KB Output is correct
56 Correct 852 ms 44464 KB Output is correct
57 Execution timed out 2572 ms 75384 KB Time limit exceeded
58 Halted 0 ms 0 KB -