이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = (1<<20);
int n, k;
vi r;
struct Seg {
ii mn[N*2]; int laz[N*2];
void build(int p=1, int l=0, int r=N-1) {
laz[p] = 0;
if(l == r) {
mn[p] = {0,l};
return;
}
int m=(l+r)/2;
build(p*2 ,l ,m);
build(p*2+1,m+1,r);
mn[p] = min(mn[p*2],mn[p*2+1]);
}
void add(int p, int v) {
laz[p] += v;
mn[p] = {mn[p].fi+v, mn[p].se};
}
void pushDown(int p) {
add(p*2 ,laz[p]);
add(p*2+1,laz[p]);
laz[p] = 0;
}
void add(int i, int j, int v, int p=1, int l=0, int r=N-1) {
if(j < l || i > r) return;
if(i <= l && j >= r) {
add(p,v);
return;
}
pushDown(p);
int m=(l+r)/2;
add(i,j,v,p*2,l,m);
add(i,j,v,p*2+1,m+1,r);
mn[p] = min(mn[p*2],mn[p*2+1]);
}
ii get(int i, int j, int p=1, int l=0, int r=N-1) {
if(j < l || i > r) return {INF,INF};
if(i <= l && j >= r) return mn[p];
pushDown(p);
int m=(l+r)/2;
ii a = get(i,j,p*2,l,m);
ii b = get(i,j,p*2+1,m+1,r);
return min(a,b);
}
void addCircle(int i, int l, int v) {
int j = i + l - 1;
add(i,min(n-1,j),v);
if(j > n-1)
add(0,j-n,v);
}
};
Seg seg1, seg2;
vi val;
void init(int k_, vi r_) {
k = k_; r = r_;
n = r.size();
seg1.build(); seg2.build();
RE(i,n) seg1.add(i,i,r[i]);
RE(i,n) seg2.add(i,i,1);
val.assign(n,0);
REV(i,0,n) {
while(true) {
ii res = seg1.get(0,n-1);
if(res.fi != 0)
break;
int j = res.se;
seg1.add(j,j,INF);
seg2.add(j,j,-1);
seg2.addCircle((j+1)%n, k-1, 1);
}
ii res = seg2.get(0,n-1);
int j = res.se;
val[j] = i;
seg2.add(j,j,INF);
seg2.addCircle((j+1)%n, k-1, -1);
seg1.addCircle((j-k+n+1)%n, k-1, -1);
}
}
int compare_plants(int x, int y) {
if(n <= 300) {
bool re[2];
RE(_,2) {
int u = _ ? x : y;
int v = _ ? y : x;
seg1.build(); seg2.build();
RE(i,n) seg1.add(i,i,r[i]);
RE(i,n) seg2.add(i,i,1);
re[_] = 0;
val.assign(n,0);
bool nRes = 1;
REV(i,0,n) {
while(true) {
ii res = seg1.get(0,n-1);
if(res.fi != 0)
break;
int j = res.se;
seg1.add(j,j,INF);
seg2.add(j,j,-1);
seg2.addCircle((j+1)%n, k-1, 1);
}
ii res = seg2.get(0,n-1);
int j = res.se;
if(seg2.get(u,u).fi == 0)
j = u, re[_] = nRes;
if(j == v)
nRes = 0;
val[j] = i;
seg2.add(j,j,INF);
seg2.addCircle((j+1)%n, k-1, -1);
seg1.addCircle((j-k+n+1)%n, k-1, -1);
}
}
if(re[0] && re[1]) return 0;
return val[x] > val[y] ? 1 : -1;
}
return val[x] > val[y] ? 1 : -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |