// vaghan ide i nadaram chi benevisam dige :/
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
const int maxn5 = 2e5 + 10;
const int maxnt = 1e6 + 10;
const int maxn3 = 310;
const int mod = 1e9 + 10;
int n, ind[maxn5];
vector <int> av, adj[maxn5], jda[maxn5];
bool mark[maxn5], mark1[maxn5], mark2[maxn5];
void dfs(int v){
mark[v] = true;
for(auto u : adj[v]) if(!mark[u])
dfs(u);
}
struct seg{
ll lazy[maxnt];
pair <ll, int> mn[maxnt];
void upd(int l, int r, int id, int val, int v){
if(r - l == 1){
lazy[v] = 0;
mn[v] = {val, l};
return;
}
int mid = (l + r) >> 1;
if(id < mid)
upd(l, mid, id, val, v * 2);
else
upd(mid, r, id, val, v * 2 + 1);
mn[v] = min(mn[v * 2], mn[v * 2 + 1]);
mn[v].fi += lazy[v];
}
void add(int l, int r, int lq, int rq, int val, int v){
if(rq <= l || r <= lq)
return;
if(lq <= l && r <= rq){
lazy[v] += val;
mn[v].fi += val;
return;
}
int mid = (l + r) >> 1;
add(l, mid, lq, rq, val, v * 2);
add(mid, r, lq, rq, val, v * 2 + 1);
mn[v] = min(mn[v * 2], mn[v * 2 + 1]);
mn[v].fi += lazy[v];
}
} seg1, seg2;
void init(int k, vector<int> r) {
n = r.size();
for(int i = 0; i < n; i++){
seg1.upd(0, n, i, r[i], 1);
seg2.upd(0, n, i, r[i], 1);
}
bool con = true;
while(con){
con = false;
while(seg1.mn[1].fi == 0){
con = true;
int v = seg1.mn[1].se;
//cout << "ok seg1 " << v << endl;
seg1.upd(0, n, v, mod / 2, 1);
if(v < n - 1)
seg2.add(0, n, v + 1, min(n, v + k), 1, 1);
if(v + k > n)
seg2.add(0, n, 0, v + k - n, 1, 1);
}
if(seg2.mn[1].fi == 0){
con = true;
int v = seg2.mn[1].se;
//cout << "ok seg2 " << v << ' ' << k << ' ' << (v - (k - 1)) << endl;
av.pb(v);
seg2.upd(0, n, v, mod / 2, 1);
if(v < n - 1)
seg2.add(0, n, v + 1, min(n, v + k), -1, 1);
if(v + k > n)
seg2.add(0, n, 0, v + k - n, -1, 1);
if(v){
seg1.add(0, n, max(0, v - (k - 1)), v, -1, 1);
seg2.add(0, n, max(0, v - (k - 1)), v, -1, 1);
}
if(v - (k - 1) < 0){
seg1.add(0, n, v - (k - 1) + n, n, -1, 1);
seg2.add(0, n, v - (k - 1) + n, n, -1, 1);
}
}
}
//cout << av.size() << endl;
reverse(all(av));
for(int i = 0; i < n; i++)
ind[av[i]] = i;
for(int i = 0; i < n; i++){
int len = k - 1, v = i;
while(len--){
v = (v + 1) % n;
if(ind[v] < ind[i])
adj[i].pb(v);
}
len = k - 1;
v = i;
while(len--){
v = (v - 1 + n) % n;
if(ind[v] < ind[i])
adj[i].pb(v);
}
}
for(int i = 0; i < n; i++) for(auto u : adj[i])
jda[u].pb(i);
dfs(0);
for(int i = 0; i < n; i++)
mark1[i] = mark[i];
for(int i = 0; i < n; i++)
swap(adj[i], jda[i]);
memset(mark, false, sizeof mark);
dfs(0);
for(int i = 0; i < n; i++)
mark2[i] = mark[i];
return;
}
int compare_plants(int x, int y) {
if(mark1[y])
return 1;
if(mark2[y])
return -1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
41144 KB |
Output is correct |
2 |
Correct |
16 ms |
41172 KB |
Output is correct |
3 |
Incorrect |
16 ms |
41216 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
41196 KB |
Output is correct |
2 |
Correct |
18 ms |
41240 KB |
Output is correct |
3 |
Incorrect |
15 ms |
41180 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
41196 KB |
Output is correct |
2 |
Correct |
18 ms |
41240 KB |
Output is correct |
3 |
Incorrect |
15 ms |
41180 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
41160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
41172 KB |
Output is correct |
2 |
Correct |
14 ms |
41172 KB |
Output is correct |
3 |
Incorrect |
17 ms |
41164 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
41168 KB |
Output is correct |
2 |
Correct |
16 ms |
41188 KB |
Output is correct |
3 |
Correct |
16 ms |
41224 KB |
Output is correct |
4 |
Correct |
16 ms |
41172 KB |
Output is correct |
5 |
Correct |
20 ms |
42452 KB |
Output is correct |
6 |
Correct |
985 ms |
290804 KB |
Output is correct |
7 |
Execution timed out |
4107 ms |
1147196 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
41144 KB |
Output is correct |
2 |
Correct |
16 ms |
41172 KB |
Output is correct |
3 |
Incorrect |
16 ms |
41216 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |