이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define SYS
#ifdef SYS
#include "plants.h"
#endif // SYS
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=300010;
struct node{
int mx,l,r,best;
};
node t[N*4];
int w[N*4];
int a[N];
int p[N];
int nn,kk;
node Merge(node A,node B){
if (A.mx>B.mx) {
return A;
}
if (A.mx<B.mx) {
return B;
}
node C;
C.mx=A.mx;
C.l=A.l;
C.r=A.r;
if (A.best!=-1) C.best=A.best;
else if (B.best!=-1) C.best=B.best;
else if (B.l>=A.r+kk) C.best=B.l;
else C.best=-1;
return C;
}
void build(int v,int l,int r){
if (l>r) return;
w[v]=0;
if (l==r){
t[v].mx=a[l];
t[v].l=t[v].r=l;
t[v].best=-1;
return;
}
int m=(l+r)/2;
build(v+v,l,m);
build(v+v+1,m+1,r);
t[v]=Merge(t[v+v],t[v+v+1]);
}
void push(int v){
t[v+v].mx+=w[v];
t[v+v+1].mx+=w[v];
w[v+v]+=w[v];
w[v+v+1]+=w[v];
w[v]=0;
}
void upd(int v,int l,int r,int L,int R,int x){
if (l>R || r<L) return;
if (l>=L && r<=R){
t[v].mx+=x;
w[v]+=x;
return;
}
push(v);
int m=(l+r)/2;
upd(v+v,l,m,L,R,x);
upd(v+v+1,m+1,r,L,R,x);
t[v]=Merge(t[v+v],t[v+v+1]);
}
void add(int n,int l,int r,int x){
if (l<=r){
upd(1,0,n-1,l,r,x);
} else {
upd(1,0,n-1,l,n-1,x);
upd(1,0,n-1,0,r,x);
}
}
vector<int>g[N];
bool can[5010][5010];
void dfs(int v,int root){
can[root][v]=true;
for (int to:g[v]){
if (!can[root][to]){
dfs(to,root);
}
}
}
void init(int k, std::vector<int> r) {
int n=r.size();
nn=n;
kk=k;
for (int &i:r){
i=k-i-1;
}
for (int i=0;i<r.size();i++) a[i]=r[i];
build(1,0,n-1);
for (int cur=n;cur>=1;cur--){
int pos=(t[1].best==-1 ? t[1].l : t[1].best);
p[pos]=cur;
// cout<<pos<<endl;
for (int i=1;i<k;i++){
int nxt=(pos-i+n)%n;
if (p[nxt]) g[nxt].push_back(pos);
else g[pos].push_back(nxt);
}
for (int i=1;i<k;i++){
int nxt=(pos+i+n)%n;
if (p[nxt]) g[nxt].push_back(pos);
else g[pos].push_back(nxt);
}
add(n,(pos-k+1+n)%n,pos,1);
add(n,pos,pos,-n*3);
}
for (int i=0;i<n;i++){
dfs(i,i);
}
return;
}
int compare_plants(int x, int y) {
if (can[x][y]) return 1;
if (can[y][x]) return -1;
return 0;
}
#ifndef SYS
#include <cstdio>
#include <cassert>
#include <vector>
static int n, k, q;
static std::vector<int> r;
static std:: vector<int> x;
static std:: vector<int> y;
static std:: vector<int> answer;
int main() {
assert(scanf("%d%d%d", &n, &k, &q) == 3);
r.resize(n);
answer.resize(q);
for (int i = 0; i < n; i++) {
int value;
assert(scanf("%d", &value) == 1);
r[i] = value;
}
x.resize(q);
y.resize(q);
for (int i = 0; i < q; i++) {
assert(scanf("%d%d", &x[i], &y[i]) == 2);
}
fclose(stdin);
init(k, r);
for (int i = 0; i < q; i++) {
answer[i] = compare_plants(x[i], y[i]);
}
for (int i = 0; i < q; i++) {
printf("%d\n", answer[i]);
}
fclose(stdout);
return 0;
}
#endif
/*
4 2 2
0 1 0 1
0 3
1 3
*/
컴파일 시 표준 에러 (stderr) 메시지
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:95:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (int i=0;i<r.size();i++) a[i]=r[i];
| ~^~~~~~~~~
# | 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... |