답안 #815315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815315 2023-08-08T14:08:15 Z MODDI 식물 비교 (IOI20_plants) C++14
27 / 100
450 ms 17108 KB
#include "plants.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
int N, K;
vi arr;
const int MAX = 200100;
struct seg_tree{
	pii tree[4*MAX];
    int lazy[4*MAX];
    void init(int node, int l, int r) {
        if(l == r) {
            tree[node].second=l;
            return;
        }
        int m = (l + r) / 2;
        init(node*2, l, m);
        init(node*2+1, m+1, r);
        tree[node]=min(tree[node*2], tree[node*2+1]);
    }
    void lazy_prop(int node, int s, int e) {
        tree[node].first+=lazy[node];
        if(s!=e) {
            lazy[node*2]+=lazy[node];
            lazy[node*2+1]+=lazy[node];
        }
        lazy[node]=0;
    }
    void update(int node, int s, int e, int l, int r, int v) {
        lazy_prop(node, s, e);
        if(s>r || e<l) return;
        if(s>=l && e<=r) {
            lazy[node]+=v;
            lazy_prop(node, s, e);
            return;
        }
        int m = (s + e) / 2;
        update(node*2, s, m, l, r, v);
        update(node*2+1, m+1, e, l, r, v);
        tree[node]=min(tree[node*2], tree[node*2+1]);
    }
    pair<int, int> query(int node, int s, int e, int l, int r) {
        lazy_prop(node, s, e);
        if(s>r || e<l) return make_pair(1e9, 0);
        if(s>=l && e<=r) return tree[node];
  
        int m = (s + e) / 2;
        return min(query(node*2, s, m, l, r), query(node*2+1, m+1, e, l, r));
    }
} tree;
vi a;
void init(int k, vector<int> r) {
	N = (int)r.size();
	a.resize(N);
	tree.init(1, 0, N-1);
	for(int i = 0; i < N; i++)	tree.update(1, 0, N-1, i, i, r[i]);
	for(int i=0; i<N; i++) {
        int pos=tree.query(1, 0, N-1, 0, N-1).second;
        if(pos>=k-1) {
            pii curr=tree.query(1, 0, N-1, pos-k+1, pos-1);
            if(curr.first==0) pos=curr.second;
        }
        else {
            pii x = tree.query(1, 0, N-1, 0, pos-1), y=tree.query(1, 0, N-1, pos-k+1+N, N-1);
            if(y.first==0) pos=y.second;
            else if(x.first==0) pos=x.second;
        }
        a[pos]=i;
        tree.update(1, 0, N-1, pos, pos, k);
        if(pos>=k-1) tree.update(1, 0, N-1, pos-k+1, pos-1, -1);
        else {
            tree.update(1, 0,N-1, 0, pos-1, -1);
            tree.update(1, 0, N-1, pos-k+1+N, N-1, -1);
        }
    }
}

int compare_plants(int x, int y) {
	if(a[x]<a[y]) return 1;
    else return -1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 5 ms 6484 KB Output is correct
3 Correct 5 ms 6564 KB Output is correct
4 Incorrect 4 ms 6568 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6484 KB Output is correct
2 Correct 5 ms 6484 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 5 ms 6576 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 6 ms 6676 KB Output is correct
7 Correct 49 ms 11420 KB Output is correct
8 Correct 5 ms 6660 KB Output is correct
9 Correct 5 ms 6612 KB Output is correct
10 Correct 54 ms 11352 KB Output is correct
11 Correct 45 ms 11240 KB Output is correct
12 Correct 45 ms 11436 KB Output is correct
13 Correct 47 ms 11320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6484 KB Output is correct
2 Correct 5 ms 6484 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 5 ms 6576 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 6 ms 6676 KB Output is correct
7 Correct 49 ms 11420 KB Output is correct
8 Correct 5 ms 6660 KB Output is correct
9 Correct 5 ms 6612 KB Output is correct
10 Correct 54 ms 11352 KB Output is correct
11 Correct 45 ms 11240 KB Output is correct
12 Correct 45 ms 11436 KB Output is correct
13 Correct 47 ms 11320 KB Output is correct
14 Correct 69 ms 12076 KB Output is correct
15 Correct 450 ms 17040 KB Output is correct
16 Correct 68 ms 12120 KB Output is correct
17 Correct 391 ms 17088 KB Output is correct
18 Correct 275 ms 16616 KB Output is correct
19 Correct 276 ms 17108 KB Output is correct
20 Correct 384 ms 17104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6568 KB Output is correct
3 Incorrect 43 ms 11148 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Incorrect 3 ms 6484 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6572 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Incorrect 3 ms 6572 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 5 ms 6484 KB Output is correct
3 Correct 5 ms 6564 KB Output is correct
4 Incorrect 4 ms 6568 KB Output isn't correct
5 Halted 0 ms 0 KB -