#include "plants.h"
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
const int N = 200100;
vector<int> glob;
int n, pre[N][2], suf[N][2];
int nxt(int x){ return (x + 1) % n;}
int get(int tp, int x) {
return (pre[x][tp] == x ? x : pre[x][tp] = get(tp, pre[x][tp]));
}
void link(int tp, int fi, int se){
fi = get(tp, fi);
se = get(tp, se);
pre[tp][fi] = se;
}
void init(int k, vector<int> r) {
assert(k == 2);
n = sz(r);
for (int i = 0; i < n; i++){
pre[i][0] = pre[i][1] = i;
}
glob = r;
for (int i = 0; i < n; i++)
if (r[i] == 0)
link(0, i, nxt(i));
else link(1, i, nxt(i));
suf[n][0] = suf[n][1] = 0;
for (int i = n - 1; i >= 0; i--){
suf[i][0] = suf[i + 1][0];
suf[i][1] = suf[i + 1][1];
suf[i][r[i] ^ 1]++;
}
return;
}
int compare_plants(int x, int y) {
if (get(0, x) == get(0, y)){
if (x > y){
if (suf[y][0] - suf[x][0] > 0)
return 1;
else return -1;
} else {
if (suf[x][0] - suf[y][0] > 0)
return -1;
else return 1;
}
}
if (get(1, x) == get(1, y)){
if (x > y){
if (suf[y][1] - suf[x][1] > 0)
return -1;
else return 1;
} else {
if (suf[x][1] - suf[y][1] > 0)
return 1;
else return -1;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1877 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |