#include "plants.h"
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rank fuck
using namespace std;
using lint = long long;
using llf = long double;
using pi = pair<lint, lint>;
const int MAXN = 200005;
int n, rank[MAXN];
lint L[MAXN], R[MAXN], DL[MAXN], DR[MAXN];
vector<int> lev[MAXN];
void init(int k, std::vector<int> r) {
n = sz(r);
int layer = 0;
int solved = 0;
while(count(rank, rank + n, 0)){
vector<int> vect;
for(int j=0; j<n; j++){
if(r[j]) continue;
bool claim = true;
for(int x=1; x<=k-1; x++){
if(r[(j-x+n)%n] == 0) claim = false;
}
if(claim) vect.push_back(j);
}
layer++;
for(auto &j : vect) if(!rank[j]) rank[j] = layer;
for(auto &j : vect){
r[j] = k - 1;
for(int x=1; x<=k-1; x++){
r[(j-x+n)%n]--;
}
}
}
for(int i=0; i<n; i++){
lev[rank[i]].push_back(i);
}
set<int> s;
for(int i=layer; i; i--){
for(auto &j : lev[i]){
auto qq = s.upper_bound(j - k);
auto rr = s.lower_bound(j + k);
int L = -1, R = -1;
if(qq != s.end() && *qq < j) L = (*qq + n) % n;
if(rr != s.begin() && *prev(rr) > j) R = *prev(rr) % n;
if(~L) DL[j] = DL[L] + (j - L + n) % n;
if(~R) DR[j] = DR[R] + (R - j + n) % n;
}
for(auto &j : lev[i]){
s.insert(j-n);
s.insert(j);
s.insert(j+n);
}
}
}
int compare_plants(int x, int y) {
if(rank[x] == rank[y]) return 0;
if(rank[x] > rank[y]) return -compare_plants(y, x);
lint st = x - DL[x];
lint ed = x + DR[x];
return st <= y && y <= ed ? 1 : 0;
}
Compilation message
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:19:6: warning: unused variable 'solved' [-Wunused-variable]
19 | int solved = 0;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
102 ms |
8224 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |