# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128560 |
2019-07-11T06:26:16 Z |
조승현(#3164) |
Rope (JOI17_rope) |
C++14 |
|
2159 ms |
80756 KB |
#include<cstdio>
#include<algorithm>
#include<vector>
#define SZ 1048576
int n, K, w[1010000], chk[1010000], IT[SZ+SZ];
using namespace std;
vector<int>G[1010000];
void Add(int a, int b){
a+=SZ;
IT[a]+=b;
while(a!=1){
a>>=1;
IT[a]=max(IT[a*2],IT[a*2+1]);
}
}
int Get(int a, int ck){
int sz = G[a].size();
vector<int>T;
int last = -ck;
for(auto &t : G[a]){
if(!chk[t]){
if((t-last)%2==0){
T.push_back(t - 1);
T.push_back(t);
chk[t-1]=chk[t]=1;
last = t;
}
else{
T.push_back(t);
T.push_back(t+1);
chk[t]=chk[t+1]=1;
last = t+1;
}
}
}
int r=0, c = n;
for(auto &t : T){
if(t<1||t>n)continue;
c--;
if(w[t]!=a)r++;
Add(w[t], -1);
}
r += c-IT[1];
for(auto &t : T){
if(t<1||t>n)continue;
Add(w[t], 1);
chk[t]=0;
}
return r;
}
int main() {
int i, j;
//freopen("input.txt","r",stdin);
scanf("%d%d",&n,&K);
for(i=1;i<=n;i++){
scanf("%d",&w[i]);
Add(w[i],1);
G[w[i]].push_back(i);
}
for(i=1;i<=K;i++){
printf("%d\n",min(Get(i,0),Get(i,1)));
}
}
/*#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
#define pii pair<int,int>
int n, K;
char p[101000];
map<pii, int>Map;
struct point {
int x, y;
};
struct AA {
int x, y;
long long z;
bool operator <(const AA &p)const{
return x!=p.x?x<p.x:y!=p.y?y<p.y:z<p.z;
}
};
vector<point> TP;
int main() {
int i, j, x = 0, y = 0;
scanf("%d%d", &n, &K);
scanf("%s", p);
Map[{0, 0}] = 1;
for (i = 0; i < n; i++) {
if (p[i] == 'E')x++;
if (p[i] == 'W')x--;
if (p[i] == 'N')y++;
if (p[i] == 'S')y--;
Map[{x, y}] = 1;
}
if (x == 0 && y == 0) {
int res = 0;
for (auto &t : Map) {
int x = t.first.first, y = t.first.second;
if (Map[{x, y}] == 1 && Map[{x + 1, y}] == 1 && Map[{x, y + 1}] == 1 && Map[{x + 1, y + 1}] == 1)res++;
}
printf("%d\n", res);
return 0;
}
for(auto &t : Map)TP.push_back({t.first.first, t.first.second});
if(x<0){
for(auto &t : TP)t.x=-t.x;
}
if(y<0){
for(auto &t : TP)t.y=-t.y;
}
for(auto &t : TP)t.x += n+1, t.y += n+1;
for(auto &t : TP){
1ll*t.x*y - 1ll*t.y*x
}
}*/
Compilation message
rope.cpp: In function 'int Get(int, int)':
rope.cpp:17:9: warning: unused variable 'sz' [-Wunused-variable]
int sz = G[a].size();
^~
rope.cpp: In function 'int main()':
rope.cpp:53:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
rope.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&K);
~~~~~^~~~~~~~~~~~~~
rope.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&w[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
23 ms |
24056 KB |
Output is correct |
3 |
Correct |
23 ms |
24056 KB |
Output is correct |
4 |
Correct |
24 ms |
24184 KB |
Output is correct |
5 |
Correct |
23 ms |
24056 KB |
Output is correct |
6 |
Correct |
24 ms |
24056 KB |
Output is correct |
7 |
Correct |
24 ms |
24056 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
23 ms |
24056 KB |
Output is correct |
10 |
Correct |
24 ms |
24056 KB |
Output is correct |
11 |
Correct |
23 ms |
24056 KB |
Output is correct |
12 |
Correct |
43 ms |
24056 KB |
Output is correct |
13 |
Correct |
28 ms |
24056 KB |
Output is correct |
14 |
Correct |
30 ms |
24056 KB |
Output is correct |
15 |
Correct |
28 ms |
24056 KB |
Output is correct |
16 |
Correct |
28 ms |
24056 KB |
Output is correct |
17 |
Correct |
24 ms |
24056 KB |
Output is correct |
18 |
Correct |
24 ms |
24056 KB |
Output is correct |
19 |
Correct |
24 ms |
24056 KB |
Output is correct |
20 |
Correct |
23 ms |
24056 KB |
Output is correct |
21 |
Correct |
30 ms |
24056 KB |
Output is correct |
22 |
Correct |
23 ms |
24056 KB |
Output is correct |
23 |
Correct |
24 ms |
24056 KB |
Output is correct |
24 |
Correct |
26 ms |
24184 KB |
Output is correct |
25 |
Correct |
24 ms |
24056 KB |
Output is correct |
26 |
Correct |
24 ms |
24184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
23 ms |
24056 KB |
Output is correct |
3 |
Correct |
23 ms |
24056 KB |
Output is correct |
4 |
Correct |
24 ms |
24184 KB |
Output is correct |
5 |
Correct |
23 ms |
24056 KB |
Output is correct |
6 |
Correct |
24 ms |
24056 KB |
Output is correct |
7 |
Correct |
24 ms |
24056 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
23 ms |
24056 KB |
Output is correct |
10 |
Correct |
24 ms |
24056 KB |
Output is correct |
11 |
Correct |
23 ms |
24056 KB |
Output is correct |
12 |
Correct |
43 ms |
24056 KB |
Output is correct |
13 |
Correct |
28 ms |
24056 KB |
Output is correct |
14 |
Correct |
30 ms |
24056 KB |
Output is correct |
15 |
Correct |
28 ms |
24056 KB |
Output is correct |
16 |
Correct |
28 ms |
24056 KB |
Output is correct |
17 |
Correct |
24 ms |
24056 KB |
Output is correct |
18 |
Correct |
24 ms |
24056 KB |
Output is correct |
19 |
Correct |
24 ms |
24056 KB |
Output is correct |
20 |
Correct |
23 ms |
24056 KB |
Output is correct |
21 |
Correct |
30 ms |
24056 KB |
Output is correct |
22 |
Correct |
23 ms |
24056 KB |
Output is correct |
23 |
Correct |
24 ms |
24056 KB |
Output is correct |
24 |
Correct |
26 ms |
24184 KB |
Output is correct |
25 |
Correct |
24 ms |
24056 KB |
Output is correct |
26 |
Correct |
24 ms |
24184 KB |
Output is correct |
27 |
Correct |
105 ms |
25852 KB |
Output is correct |
28 |
Correct |
102 ms |
26024 KB |
Output is correct |
29 |
Correct |
105 ms |
25920 KB |
Output is correct |
30 |
Correct |
103 ms |
26084 KB |
Output is correct |
31 |
Correct |
104 ms |
25940 KB |
Output is correct |
32 |
Correct |
101 ms |
26016 KB |
Output is correct |
33 |
Correct |
104 ms |
25848 KB |
Output is correct |
34 |
Correct |
105 ms |
26124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
23 ms |
24056 KB |
Output is correct |
3 |
Correct |
23 ms |
24056 KB |
Output is correct |
4 |
Correct |
24 ms |
24184 KB |
Output is correct |
5 |
Correct |
23 ms |
24056 KB |
Output is correct |
6 |
Correct |
24 ms |
24056 KB |
Output is correct |
7 |
Correct |
24 ms |
24056 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
23 ms |
24056 KB |
Output is correct |
10 |
Correct |
24 ms |
24056 KB |
Output is correct |
11 |
Correct |
23 ms |
24056 KB |
Output is correct |
12 |
Correct |
43 ms |
24056 KB |
Output is correct |
13 |
Correct |
28 ms |
24056 KB |
Output is correct |
14 |
Correct |
30 ms |
24056 KB |
Output is correct |
15 |
Correct |
28 ms |
24056 KB |
Output is correct |
16 |
Correct |
28 ms |
24056 KB |
Output is correct |
17 |
Correct |
24 ms |
24056 KB |
Output is correct |
18 |
Correct |
24 ms |
24056 KB |
Output is correct |
19 |
Correct |
24 ms |
24056 KB |
Output is correct |
20 |
Correct |
23 ms |
24056 KB |
Output is correct |
21 |
Correct |
30 ms |
24056 KB |
Output is correct |
22 |
Correct |
23 ms |
24056 KB |
Output is correct |
23 |
Correct |
24 ms |
24056 KB |
Output is correct |
24 |
Correct |
26 ms |
24184 KB |
Output is correct |
25 |
Correct |
24 ms |
24056 KB |
Output is correct |
26 |
Correct |
24 ms |
24184 KB |
Output is correct |
27 |
Correct |
105 ms |
25852 KB |
Output is correct |
28 |
Correct |
102 ms |
26024 KB |
Output is correct |
29 |
Correct |
105 ms |
25920 KB |
Output is correct |
30 |
Correct |
103 ms |
26084 KB |
Output is correct |
31 |
Correct |
104 ms |
25940 KB |
Output is correct |
32 |
Correct |
101 ms |
26016 KB |
Output is correct |
33 |
Correct |
104 ms |
25848 KB |
Output is correct |
34 |
Correct |
105 ms |
26124 KB |
Output is correct |
35 |
Correct |
101 ms |
25848 KB |
Output is correct |
36 |
Correct |
100 ms |
25820 KB |
Output is correct |
37 |
Correct |
100 ms |
25848 KB |
Output is correct |
38 |
Correct |
101 ms |
25948 KB |
Output is correct |
39 |
Correct |
101 ms |
25848 KB |
Output is correct |
40 |
Correct |
103 ms |
26076 KB |
Output is correct |
41 |
Correct |
96 ms |
25848 KB |
Output is correct |
42 |
Correct |
96 ms |
25976 KB |
Output is correct |
43 |
Correct |
97 ms |
25936 KB |
Output is correct |
44 |
Correct |
103 ms |
25848 KB |
Output is correct |
45 |
Correct |
96 ms |
25848 KB |
Output is correct |
46 |
Correct |
103 ms |
25916 KB |
Output is correct |
47 |
Correct |
96 ms |
25848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
23 ms |
24056 KB |
Output is correct |
3 |
Correct |
23 ms |
24056 KB |
Output is correct |
4 |
Correct |
24 ms |
24184 KB |
Output is correct |
5 |
Correct |
23 ms |
24056 KB |
Output is correct |
6 |
Correct |
24 ms |
24056 KB |
Output is correct |
7 |
Correct |
24 ms |
24056 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
23 ms |
24056 KB |
Output is correct |
10 |
Correct |
24 ms |
24056 KB |
Output is correct |
11 |
Correct |
23 ms |
24056 KB |
Output is correct |
12 |
Correct |
43 ms |
24056 KB |
Output is correct |
13 |
Correct |
28 ms |
24056 KB |
Output is correct |
14 |
Correct |
30 ms |
24056 KB |
Output is correct |
15 |
Correct |
28 ms |
24056 KB |
Output is correct |
16 |
Correct |
28 ms |
24056 KB |
Output is correct |
17 |
Correct |
24 ms |
24056 KB |
Output is correct |
18 |
Correct |
24 ms |
24056 KB |
Output is correct |
19 |
Correct |
24 ms |
24056 KB |
Output is correct |
20 |
Correct |
23 ms |
24056 KB |
Output is correct |
21 |
Correct |
30 ms |
24056 KB |
Output is correct |
22 |
Correct |
23 ms |
24056 KB |
Output is correct |
23 |
Correct |
24 ms |
24056 KB |
Output is correct |
24 |
Correct |
26 ms |
24184 KB |
Output is correct |
25 |
Correct |
24 ms |
24056 KB |
Output is correct |
26 |
Correct |
24 ms |
24184 KB |
Output is correct |
27 |
Correct |
105 ms |
25852 KB |
Output is correct |
28 |
Correct |
102 ms |
26024 KB |
Output is correct |
29 |
Correct |
105 ms |
25920 KB |
Output is correct |
30 |
Correct |
103 ms |
26084 KB |
Output is correct |
31 |
Correct |
104 ms |
25940 KB |
Output is correct |
32 |
Correct |
101 ms |
26016 KB |
Output is correct |
33 |
Correct |
104 ms |
25848 KB |
Output is correct |
34 |
Correct |
105 ms |
26124 KB |
Output is correct |
35 |
Correct |
101 ms |
25848 KB |
Output is correct |
36 |
Correct |
100 ms |
25820 KB |
Output is correct |
37 |
Correct |
100 ms |
25848 KB |
Output is correct |
38 |
Correct |
101 ms |
25948 KB |
Output is correct |
39 |
Correct |
101 ms |
25848 KB |
Output is correct |
40 |
Correct |
103 ms |
26076 KB |
Output is correct |
41 |
Correct |
96 ms |
25848 KB |
Output is correct |
42 |
Correct |
96 ms |
25976 KB |
Output is correct |
43 |
Correct |
97 ms |
25936 KB |
Output is correct |
44 |
Correct |
103 ms |
25848 KB |
Output is correct |
45 |
Correct |
96 ms |
25848 KB |
Output is correct |
46 |
Correct |
103 ms |
25916 KB |
Output is correct |
47 |
Correct |
96 ms |
25848 KB |
Output is correct |
48 |
Correct |
904 ms |
41508 KB |
Output is correct |
49 |
Correct |
900 ms |
41336 KB |
Output is correct |
50 |
Correct |
893 ms |
41588 KB |
Output is correct |
51 |
Correct |
880 ms |
41464 KB |
Output is correct |
52 |
Correct |
871 ms |
40540 KB |
Output is correct |
53 |
Correct |
823 ms |
40696 KB |
Output is correct |
54 |
Correct |
825 ms |
39672 KB |
Output is correct |
55 |
Correct |
827 ms |
39460 KB |
Output is correct |
56 |
Correct |
832 ms |
39280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
23 ms |
24056 KB |
Output is correct |
3 |
Correct |
23 ms |
24056 KB |
Output is correct |
4 |
Correct |
24 ms |
24184 KB |
Output is correct |
5 |
Correct |
23 ms |
24056 KB |
Output is correct |
6 |
Correct |
24 ms |
24056 KB |
Output is correct |
7 |
Correct |
24 ms |
24056 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
23 ms |
24056 KB |
Output is correct |
10 |
Correct |
24 ms |
24056 KB |
Output is correct |
11 |
Correct |
23 ms |
24056 KB |
Output is correct |
12 |
Correct |
43 ms |
24056 KB |
Output is correct |
13 |
Correct |
28 ms |
24056 KB |
Output is correct |
14 |
Correct |
30 ms |
24056 KB |
Output is correct |
15 |
Correct |
28 ms |
24056 KB |
Output is correct |
16 |
Correct |
28 ms |
24056 KB |
Output is correct |
17 |
Correct |
24 ms |
24056 KB |
Output is correct |
18 |
Correct |
24 ms |
24056 KB |
Output is correct |
19 |
Correct |
24 ms |
24056 KB |
Output is correct |
20 |
Correct |
23 ms |
24056 KB |
Output is correct |
21 |
Correct |
30 ms |
24056 KB |
Output is correct |
22 |
Correct |
23 ms |
24056 KB |
Output is correct |
23 |
Correct |
24 ms |
24056 KB |
Output is correct |
24 |
Correct |
26 ms |
24184 KB |
Output is correct |
25 |
Correct |
24 ms |
24056 KB |
Output is correct |
26 |
Correct |
24 ms |
24184 KB |
Output is correct |
27 |
Correct |
105 ms |
25852 KB |
Output is correct |
28 |
Correct |
102 ms |
26024 KB |
Output is correct |
29 |
Correct |
105 ms |
25920 KB |
Output is correct |
30 |
Correct |
103 ms |
26084 KB |
Output is correct |
31 |
Correct |
104 ms |
25940 KB |
Output is correct |
32 |
Correct |
101 ms |
26016 KB |
Output is correct |
33 |
Correct |
104 ms |
25848 KB |
Output is correct |
34 |
Correct |
105 ms |
26124 KB |
Output is correct |
35 |
Correct |
101 ms |
25848 KB |
Output is correct |
36 |
Correct |
100 ms |
25820 KB |
Output is correct |
37 |
Correct |
100 ms |
25848 KB |
Output is correct |
38 |
Correct |
101 ms |
25948 KB |
Output is correct |
39 |
Correct |
101 ms |
25848 KB |
Output is correct |
40 |
Correct |
103 ms |
26076 KB |
Output is correct |
41 |
Correct |
96 ms |
25848 KB |
Output is correct |
42 |
Correct |
96 ms |
25976 KB |
Output is correct |
43 |
Correct |
97 ms |
25936 KB |
Output is correct |
44 |
Correct |
103 ms |
25848 KB |
Output is correct |
45 |
Correct |
96 ms |
25848 KB |
Output is correct |
46 |
Correct |
103 ms |
25916 KB |
Output is correct |
47 |
Correct |
96 ms |
25848 KB |
Output is correct |
48 |
Correct |
904 ms |
41508 KB |
Output is correct |
49 |
Correct |
900 ms |
41336 KB |
Output is correct |
50 |
Correct |
893 ms |
41588 KB |
Output is correct |
51 |
Correct |
880 ms |
41464 KB |
Output is correct |
52 |
Correct |
871 ms |
40540 KB |
Output is correct |
53 |
Correct |
823 ms |
40696 KB |
Output is correct |
54 |
Correct |
825 ms |
39672 KB |
Output is correct |
55 |
Correct |
827 ms |
39460 KB |
Output is correct |
56 |
Correct |
832 ms |
39280 KB |
Output is correct |
57 |
Correct |
2159 ms |
80756 KB |
Output is correct |
58 |
Correct |
1872 ms |
63212 KB |
Output is correct |
59 |
Correct |
1959 ms |
63068 KB |
Output is correct |
60 |
Correct |
1976 ms |
67692 KB |
Output is correct |
61 |
Correct |
2025 ms |
67960 KB |
Output is correct |
62 |
Correct |
1295 ms |
52472 KB |
Output is correct |
63 |
Correct |
1581 ms |
57360 KB |
Output is correct |
64 |
Correct |
1340 ms |
54436 KB |
Output is correct |
65 |
Correct |
1101 ms |
46432 KB |
Output is correct |