#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "plants.h"
struct MINARGSEGTREE {
int n;
VPI tree;
VI lazy;
MINARGSEGTREE(){}
MINARGSEGTREE(int sz) {
n = 1;
while (n < sz) n *= 2;
tree = VPI(2*n, {+1e9, -1});
lazy = VI(2*n);
}
void push(int N) {
tree[N].ff += lazy[N];
if (2*N+2 < 2*n) {
lazy[2*N+1] += lazy[N];
lazy[2*N+2] += lazy[N];
}
lazy[N] = 0;
}
void set(int N, int L, int R, int i, PII s) {
push(N);
if (i < L || i > R) return;
if (L == R) {
tree[N] = s;
return;
}
int M = (L + R) / 2;
set(2*N+1, L, M, i, s);
set(2*N+2, M+1, R, i, s);
tree[N] = min(tree[2*N+1], tree[2*N+2]);
}
void add(int N, int L, int R, int l, int r, int s) {
push(N);
if (R < l || L > r) return;
if (l <= L && R <= r) {
lazy[N] = s;
push(N);
return;
}
int M = (L + R) / 2;
add(2*N+1, L, M, l, r, s);
add(2*N+2, M+1, R, l, r, s);
tree[N] = min(tree[2*N+1], tree[2*N+2]);
}
PII get(int N, int L, int R, int l, int r) {
push(N);
if (l <= L && R <= r) return tree[N];
if (R < l || L > r) return {+1e9, -1};
int M = (L + R) / 2;
return min(get(2*N+1, L, M, l, r), get(2*N+2, M+1, R, l, r));
}
void set(int i, int s) {
set(0, 0, n-1, i, {s, i});
}
void add(int l, int r, int s) {
add(0, 0, n-1, l, r, s);
}
PII get(int l, int r) {
return get(0, 0, n-1, l, r);
}
};
struct FIRSTZERODS {
int n;
MINARGSEGTREE seg;
FIRSTZERODS(){}
FIRSTZERODS(VI a) {
n = a.size();
seg = MINARGSEGTREE(n);
rep(i, n) seg.set(i, a[i]);
}
void remove(int i) {
seg.set(i, +1e9);
}
void decrement(int l, int r) {
l = (l+100*n)%n;
r = (r+100*n)%n;
if (l <= r) seg.add(l, r, -1);
else {
seg.add(l, n-1, -1);
seg.add(0, r, -1);
}
}
int get(int l, int r) {
l = (l+100*n)%n;
r = (r+100*n)%n;
PII ret;
if (l <= r) ret = seg.get(l, r);
else {
ret = seg.get(l, n-1);
if (ret.ff) ret = seg.get(0, r);
}
if (ret.ff == 0) return ret.ss;
return -1;
}
void print() {
rep(i, n) cout << seg.get(i, i).ff << " "; cout << endl;
}
};
int n, k;
FIRSTZERODS seg;
VI a;
int mx;
VVI gp;
void extract(int i) {
while (true) {
int prev = seg.get(i-k+1, i-1);
if (prev == -1) break;
extract(prev);
}
a[i] = mx--;
seg.remove(i);
seg.decrement(i-k+1, i-1);
}
void init(int K_ARG, VI r) {
k = K_ARG;
n = r.size();
seg = FIRSTZERODS(r);
a = VI(n, -1);
mx = n-1;
while (mx >= 0) extract(seg.get(0, n-1));
if (n <= 300) {
gp = VVI(n, VI(n));
rep(i, n) replr(jwm, i+1, i+k-1) {
int j = jwm%n;
if (a[j] > a[i]) gp[i][j] = true;
else gp[j][i] = true;
}
rep(m, n) rep(u, n) rep(v, n) {
gp[u][v] |= gp[u][m] && gp[m][v];
}
}
}
int compare_plants(int x, int y) {
if (n <= 300) {
if (gp[y][x]) return +1;
if (gp[x][y]) return -1;
return 0;
}
if (a[x] > a[y]) return +1;
if (a[x] < a[y]) return -1;
return 0;
}
Compilation message
plants.cpp: In member function 'void FIRSTZERODS::print()':
plants.cpp:9:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
| ^~~
plants.cpp:129:9: note: in expansion of macro 'rep'
129 | rep(i, n) cout << seg.get(i, i).ff << " "; cout << endl;
| ^~~
plants.cpp:129:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
129 | rep(i, n) cout << seg.get(i, i).ff << " "; cout << endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
33 ms |
4184 KB |
Output is correct |
7 |
Incorrect |
52 ms |
6184 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
41 ms |
3280 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
39 ms |
3324 KB |
Output is correct |
11 |
Correct |
34 ms |
3324 KB |
Output is correct |
12 |
Correct |
37 ms |
3408 KB |
Output is correct |
13 |
Correct |
39 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
41 ms |
3280 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
39 ms |
3324 KB |
Output is correct |
11 |
Correct |
34 ms |
3324 KB |
Output is correct |
12 |
Correct |
37 ms |
3408 KB |
Output is correct |
13 |
Correct |
39 ms |
3408 KB |
Output is correct |
14 |
Correct |
72 ms |
4176 KB |
Output is correct |
15 |
Correct |
441 ms |
11280 KB |
Output is correct |
16 |
Correct |
67 ms |
4060 KB |
Output is correct |
17 |
Correct |
423 ms |
11092 KB |
Output is correct |
18 |
Correct |
314 ms |
11100 KB |
Output is correct |
19 |
Correct |
335 ms |
11244 KB |
Output is correct |
20 |
Correct |
437 ms |
11088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
35 ms |
4456 KB |
Output is correct |
4 |
Correct |
250 ms |
15168 KB |
Output is correct |
5 |
Correct |
312 ms |
14568 KB |
Output is correct |
6 |
Correct |
344 ms |
14440 KB |
Output is correct |
7 |
Correct |
400 ms |
14560 KB |
Output is correct |
8 |
Correct |
424 ms |
14932 KB |
Output is correct |
9 |
Correct |
271 ms |
14292 KB |
Output is correct |
10 |
Correct |
294 ms |
14180 KB |
Output is correct |
11 |
Correct |
218 ms |
14188 KB |
Output is correct |
12 |
Correct |
245 ms |
14164 KB |
Output is correct |
13 |
Correct |
303 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
35 ms |
1656 KB |
Output is correct |
8 |
Correct |
33 ms |
1628 KB |
Output is correct |
9 |
Correct |
53 ms |
1624 KB |
Output is correct |
10 |
Correct |
34 ms |
1692 KB |
Output is correct |
11 |
Correct |
35 ms |
1628 KB |
Output is correct |
12 |
Correct |
35 ms |
1628 KB |
Output is correct |
13 |
Correct |
35 ms |
1596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
33 ms |
4184 KB |
Output is correct |
7 |
Incorrect |
52 ms |
6184 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |