답안 #304441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304441 2020-09-21T11:11:04 Z mhy908 식물 비교 (IOI20_plants) C++14
5 / 100
1446 ms 34892 KB
#include "plants.h"
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(all(x))
#define press(x) x.erase(unique(all(x)), x.end());
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int INF=1e9;
const LL LLINF=1e18;

int n, k;
vector<int> vc1, vc2;

struct LAZY_SEG{
    LL tree[1600010], lazy[1600010];
    void prop(int point, int s, int e){
        if(s==e)tree[point]+=lazy[point];
        else{
            lazy[point*2]+=lazy[point];
            lazy[point*2+1]+=lazy[point];
        }
        lazy[point]=0;
    }
    void eat(int point){
        tree[point]=min(tree[point*2]+lazy[point*2], tree[point*2+1]+lazy[point*2+1]);
    }
    void init(){
        memset(tree, 0, sizeof tree);
        memset(lazy, 0, sizeof lazy);
    }
    void alter(int point, int s, int e, int a, int b, LL val){
        if(e<a||s>b)return;
        if(a<=s&&e<=b){
            lazy[point]+=val;
            return;
        }
        prop(point, s, e);
        alter(point*2, s, (s+e)/2, a, b, val);
        alter(point*2+1, (s+e)/2+1, e, a, b, val);
        eat(point);
    }
    int argmin(int point, int s, int e){
        if(tree[point]+lazy[point]>0)return -1;
        if(s==e)return s;
        prop(point, s, e);
        int ret=argmin(point*2, s, (s+e)/2);
        if(ret<0)ret=argmin(point*2+1, (s+e)/2+1, e);
        eat(point);
        return ret;
    }
}seg;

int stk[400010], re;

vector<int> calc(vector<int> vc){
    vector<int> ret;
    ret.resize(vc.size());
    re=0;
    seg.init();
    for(int i=0; i<2*n; i++){
        seg.alter(1, 0, 2*n-1, i, i, (LL)vc[i]);
    }
    for(int i=1; i<=2*n; i++){
        int x;
        while(1){
            x=seg.argmin(1, 0, 2*n-1);
            if(x>=0)break;
            seg.alter(1, 0, 2*n-1, stk[re], 2*n-1, -1);
            re--;
        }
        ret[x]=i;
        seg.alter(1, 0, 2*n-1, x, x, LLINF);
        seg.alter(1, 0, 2*n-1, x-k+1, x-1, -1);
        if(x-k+1<0)stk[++re]=2*n-x+k-2;
    }
    return ret;
}

void init(int _k, vector<int> r) {
	n=r.size(); k=_k;
	for(int i=0; i<n; i++)r.eb(r[i]);
	vc1=calc(r);
	for(int i=0; i<2*n; i++)r[i]=k-1-r[i];
	vc2=calc(r);
}

int compare_plants(int x, int y){
	if(x>y)return -compare_plants(y, x);
    if(vc1[x]>vc1[y]||vc2[x+n]<vc2[y])return -1;
    if(vc2[x]>vc2[y]||vc1[x+n]<vc1[y])return 1;
    return 0;
}

/*
4 3 2
0 1 1 2
0 2
1 2
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25344 KB Output is correct
2 Correct 18 ms 25344 KB Output is correct
3 Correct 18 ms 25344 KB Output is correct
4 Correct 18 ms 25344 KB Output is correct
5 Correct 18 ms 25344 KB Output is correct
6 Correct 81 ms 28280 KB Output is correct
7 Correct 167 ms 28728 KB Output is correct
8 Correct 988 ms 34780 KB Output is correct
9 Correct 995 ms 34764 KB Output is correct
10 Correct 987 ms 34764 KB Output is correct
11 Correct 984 ms 34764 KB Output is correct
12 Correct 981 ms 34892 KB Output is correct
13 Correct 979 ms 34764 KB Output is correct
14 Correct 979 ms 34892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25344 KB Output is correct
2 Correct 18 ms 25344 KB Output is correct
3 Correct 18 ms 25344 KB Output is correct
4 Correct 18 ms 25344 KB Output is correct
5 Incorrect 18 ms 25344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25344 KB Output is correct
2 Correct 18 ms 25344 KB Output is correct
3 Correct 18 ms 25344 KB Output is correct
4 Correct 18 ms 25344 KB Output is correct
5 Incorrect 18 ms 25344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25344 KB Output is correct
2 Correct 18 ms 25344 KB Output is correct
3 Correct 94 ms 28408 KB Output is correct
4 Correct 1039 ms 34892 KB Output is correct
5 Correct 1141 ms 34764 KB Output is correct
6 Incorrect 1446 ms 34764 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25336 KB Output is correct
2 Correct 18 ms 25344 KB Output is correct
3 Correct 18 ms 25344 KB Output is correct
4 Correct 18 ms 25344 KB Output is correct
5 Correct 18 ms 25344 KB Output is correct
6 Correct 20 ms 25472 KB Output is correct
7 Correct 33 ms 25984 KB Output is correct
8 Incorrect 34 ms 25984 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25344 KB Output is correct
2 Correct 18 ms 25344 KB Output is correct
3 Correct 18 ms 25344 KB Output is correct
4 Correct 18 ms 25344 KB Output is correct
5 Incorrect 22 ms 25344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25344 KB Output is correct
2 Correct 18 ms 25344 KB Output is correct
3 Correct 18 ms 25344 KB Output is correct
4 Correct 18 ms 25344 KB Output is correct
5 Correct 18 ms 25344 KB Output is correct
6 Correct 81 ms 28280 KB Output is correct
7 Correct 167 ms 28728 KB Output is correct
8 Correct 988 ms 34780 KB Output is correct
9 Correct 995 ms 34764 KB Output is correct
10 Correct 987 ms 34764 KB Output is correct
11 Correct 984 ms 34764 KB Output is correct
12 Correct 981 ms 34892 KB Output is correct
13 Correct 979 ms 34764 KB Output is correct
14 Correct 979 ms 34892 KB Output is correct
15 Correct 18 ms 25344 KB Output is correct
16 Correct 18 ms 25344 KB Output is correct
17 Correct 18 ms 25344 KB Output is correct
18 Correct 18 ms 25344 KB Output is correct
19 Incorrect 18 ms 25344 KB Output isn't correct
20 Halted 0 ms 0 KB -