답안 #815236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815236 2023-08-08T13:23:55 Z lkh3happy 식물 비교 (IOI20_plants) C++14
0 / 100
1 ms 304 KB
//#include "plants.h"
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int r[222222], lz[888888], rnk[222222], k;
pair<int, int> t[888888];

void scl(int l, int r, int n){
    t[n]={0, l};
    lz[n]=0;
    if(l==r) return;
    int m=l+r>>1;
    scl(l, m, n*2); scl(m+1, r, n*2+1);
}

void lzup(int l, int r, int n){
    t[n].first+=lz[n];
    if(l^r) lz[n*2]+=lz[n], lz[n*2+1]+=lz[n];
    lz[n]=0;
}

void upd(int l, int r, int n, int s, int e, int x){
    lzup(l, r, n);
    if(r<s || e<l) return;
    if(s<=l && r<=e){
        lz[n]+=x;
        lzup(l, r, n);
        return;
    }
    int m=l+r>>1;
    upd(l, m, n*2, s, e, x); upd(m+1, r, n*2+1, s, e, x);
    t[n]=min(t[n*2], t[n*2+1]);
}

pair<int, int> mn(int l, int r, int n, int s, int e){
    lzup(l, r, n);
    if(r<s || e<l) return {1e9, 1e9};
    if(s<=l && r<=e) return t[n];
    int m=l+r>>1;
    return min(mn(l, m, n*2, s, e), mn(m+1, r, n*2+1, s, e));
}

pair<int, int> fmn(int l, int r, int n, int s, int e){
    if(e<1) return mn(l, r, n, r+s, r+e);
    if(s>r) return mn(l, r, n, s-r, e-r);
    if(e>r){
        pair<int, int> x=mn(l, r, n, s, r);
        if(!x.first) return x;
        return min(x, mn(l, r, n, 1, e-r));
    }
    if(s<1){
        pair<int, int> x=mn(l, r, n, r+s, r);
        if(!x.first) return x;
        return min(mn(l, r, n, 1, e), x);
    }
    return mn(l, r, n, s, e);
}

void fupd(int l, int r, int n, int s, int e, int x){
    if(s>0 && e<=r) return upd(l, r, n, s, e, x);
    if(e<1) return upd(l, r, n, r+s, r+e, x);
    if(s>r) return upd(l, r, n, s-r, e-r, x);
    if(e>r) return upd(l, r, n, s, r, x), upd(l, r, n, 1, e-r, x);
    if(s<1) return upd(l, r, n, 1, e, x), upd(l, r, n, r+s, r, x);
}

void init(int _k, vector<int> _r){
    int n=_r.size(), k=_k;
    scl(1, n, 1);
    vector<int> v;
    for(int i=1;i<=n;i++) r[i]=_r[i-1], upd(1, n, 1, i, i, r[i]);
    for(int i=1;i<=n;i++) if(!r[i] && fmn(1, n, 1, i-k+1, i-1).first) rnk[i]=1, v.push_back(i);
    for(int i=0;i<v.size();i++){
        fupd(1, n, 1, v[i]-k+1, v[i]-1, -1); fupd(1, n, 1, v[i], v[i], 1e9);
        pair<int, int> lx=fmn(1, n, 1, v[i]-k+1, v[i]-1), rx=fmn(1, n, 1, v[i]+1, v[i]+k-1);
        if(!lx.first && fmn(1, n, 1, lx.second-k+1, i-1).first) rnk[lx.second]=rnk[v[i]]+1, v.push_back(lx.second);
        if(!rx.first && fmn(1, n, 1, rx.second-k+1, i-1).first) rnk[rx.second]=rnk[v[i]]+1, v.push_back(rx.second);
    }
	return;
}

int compare_plants(int x, int y){
    x++; y++;
	return (rnk[x]>rnk[y])?-1:1;
}

Compilation message

plants.cpp: In function 'void scl(int, int, int)':
plants.cpp:14:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   14 |     int m=l+r>>1;
      |           ~^~
plants.cpp: In function 'void upd(int, int, int, int, int, int)':
plants.cpp:32:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int m=l+r>>1;
      |           ~^~
plants.cpp: In function 'std::pair<int, int> mn(int, int, int, int, int)':
plants.cpp:41:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |     int m=l+r>>1;
      |           ~^~
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:75:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 304 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 304 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 292 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -