# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128557 |
2019-07-11T06:22:10 Z |
조승현(#3164) |
Rope (JOI17_rope) |
C++14 |
|
24 ms |
24056 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;
}
}
}
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){
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:51:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
rope.cpp:53: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:55: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 |
24 ms |
24056 KB |
Output is correct |
3 |
Incorrect |
24 ms |
24056 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
24 ms |
24056 KB |
Output is correct |
3 |
Incorrect |
24 ms |
24056 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
24 ms |
24056 KB |
Output is correct |
3 |
Incorrect |
24 ms |
24056 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
24 ms |
24056 KB |
Output is correct |
3 |
Incorrect |
24 ms |
24056 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
24056 KB |
Output is correct |
2 |
Correct |
24 ms |
24056 KB |
Output is correct |
3 |
Incorrect |
24 ms |
24056 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |