답안 #480511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480511 2021-10-16T17:49:11 Z couplefire 식물 비교 (IOI20_plants) C++17
100 / 100
296 ms 15996 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
const int n_bits=18;
const int inf = 1e9;
const int n_max = 2e5+5;
int arr[1<<(n_bits+1)];
int lazyadd[1<<(n_bits+1)];
int p_lt[n_max];
int p_rg[n_max];
int stash[n_max]; // a manual queue
int tallest[n_max];
int shortest[n_max];
 
struct segtree {
    int node = 1;
    int lazy = 0;
    segtree(){}
    void build(vector<int> &v) {
        assert(v.size()<(1<<n_bits));
        for(int i=0; i<(1<<n_bits); i++) {
            arr[i+(1<<n_bits)] = (i<(int)v.size() ? v[i] : inf);
        }
        for(int i=(1<<n_bits)-1; i>=1; i--) {
            arr[i] = min(arr[2*i], arr[2*i+1]);
        }
        for(int i=0; i<(1<<(n_bits+1)); i++) {
            lazyadd[i] = 0;
        }
    }
 
    void prefix_update(int x, int change) {
        if(x==-1) return;
        x += (1<<n_bits);
        lazyadd[x] += change;
        for(int i=0; i<n_bits; i++) {
            if(x&1) {
                lazyadd[x-1] += change;
            }
            arr[x/2] = min(arr[x]+lazyadd[x], arr[x^1]+lazyadd[x^1]);
            x=x/2;
        }
    }
 
    void decr(int left, int right) {
        prefix_update(left-1, 1);
        prefix_update(right,-1);
    }
 
    int find_and_remove_zero() {
        node = 1;
        lazy = 0;
        for(int i=0; i<n_bits; i++) {
            lazy += lazyadd[node];
            node *= 2;
            if(lazy + lazyadd[node] + arr[node]) node++;
        }
        int ans = node - (1<<n_bits);
        lazyadd[node] = 1e9;
        for(int i=0; i<n_bits; i++) {
            arr[node/2] = min(arr[node]+lazyadd[node], arr[node^1]+lazyadd[node^1]);
            node = node/2;
        }
        return ans;
    }
};
 
void lexi_smallest(int k, vector<int> &r, int* ptr, int* ord) {
    segtree s;
    s.build(r);
    int n = r.size();
    stash[0] = n;
    ord[n] = -1;
    int* fr = stash+1;
    int* bk = stash+1;
    for(int i=0; i<(int)r.size(); i++) {
        while(lazyadd[1] + arr[1]) {
            s.decr((*fr++)-k+1+n, n-1);
        }
        int p = s.find_and_remove_zero();
        ord[p] = i;
        if(p<k-1) {
            s.prefix_update(p, -1);
            *bk++ = p;
        } else {
            s.decr(p-k+1, p);
        }
        ptr[p] = ord[*(fr-1)];
    }
}
void init(int k, std::vector<int> r) {
    lexi_smallest(k,r,p_lt, tallest);
    for(int &i: r) i = k-1-i;
    lexi_smallest(k,r,p_rg, shortest);
}
 
int compare_plants(int x, int y) {
    if(x>y) return -compare_plants(y,x);
    if(tallest[x]>tallest[y] || p_rg[y]>=shortest[x]) return -1;
    if(shortest[x]>shortest[y] || p_lt[y]>=tallest[x]) return 1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4428 KB Output is correct
2 Correct 4 ms 4428 KB Output is correct
3 Correct 4 ms 4428 KB Output is correct
4 Correct 3 ms 4428 KB Output is correct
5 Correct 6 ms 4428 KB Output is correct
6 Correct 62 ms 8152 KB Output is correct
7 Correct 76 ms 9776 KB Output is correct
8 Correct 187 ms 14276 KB Output is correct
9 Correct 188 ms 14300 KB Output is correct
10 Correct 196 ms 14276 KB Output is correct
11 Correct 192 ms 14340 KB Output is correct
12 Correct 188 ms 14276 KB Output is correct
13 Correct 189 ms 14328 KB Output is correct
14 Correct 182 ms 14304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4428 KB Output is correct
2 Correct 3 ms 4428 KB Output is correct
3 Correct 4 ms 4428 KB Output is correct
4 Correct 4 ms 4428 KB Output is correct
5 Correct 4 ms 4428 KB Output is correct
6 Correct 6 ms 4556 KB Output is correct
7 Correct 69 ms 9204 KB Output is correct
8 Correct 5 ms 4428 KB Output is correct
9 Correct 6 ms 4556 KB Output is correct
10 Correct 63 ms 9196 KB Output is correct
11 Correct 57 ms 9156 KB Output is correct
12 Correct 89 ms 9296 KB Output is correct
13 Correct 65 ms 9196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4428 KB Output is correct
2 Correct 3 ms 4428 KB Output is correct
3 Correct 4 ms 4428 KB Output is correct
4 Correct 4 ms 4428 KB Output is correct
5 Correct 4 ms 4428 KB Output is correct
6 Correct 6 ms 4556 KB Output is correct
7 Correct 69 ms 9204 KB Output is correct
8 Correct 5 ms 4428 KB Output is correct
9 Correct 6 ms 4556 KB Output is correct
10 Correct 63 ms 9196 KB Output is correct
11 Correct 57 ms 9156 KB Output is correct
12 Correct 89 ms 9296 KB Output is correct
13 Correct 65 ms 9196 KB Output is correct
14 Correct 84 ms 10056 KB Output is correct
15 Correct 282 ms 15640 KB Output is correct
16 Correct 76 ms 9892 KB Output is correct
17 Correct 290 ms 15776 KB Output is correct
18 Correct 190 ms 15124 KB Output is correct
19 Correct 183 ms 15564 KB Output is correct
20 Correct 295 ms 15996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4428 KB Output is correct
2 Correct 3 ms 4428 KB Output is correct
3 Correct 62 ms 8976 KB Output is correct
4 Correct 197 ms 14276 KB Output is correct
5 Correct 216 ms 14432 KB Output is correct
6 Correct 233 ms 14660 KB Output is correct
7 Correct 265 ms 15080 KB Output is correct
8 Correct 284 ms 15392 KB Output is correct
9 Correct 195 ms 14404 KB Output is correct
10 Correct 196 ms 14556 KB Output is correct
11 Correct 194 ms 14304 KB Output is correct
12 Correct 211 ms 14532 KB Output is correct
13 Correct 197 ms 14816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4428 KB Output is correct
2 Correct 4 ms 4428 KB Output is correct
3 Correct 4 ms 4428 KB Output is correct
4 Correct 3 ms 4428 KB Output is correct
5 Correct 4 ms 4428 KB Output is correct
6 Correct 5 ms 4428 KB Output is correct
7 Correct 22 ms 5256 KB Output is correct
8 Correct 16 ms 5376 KB Output is correct
9 Correct 15 ms 5328 KB Output is correct
10 Correct 16 ms 5292 KB Output is correct
11 Correct 18 ms 5324 KB Output is correct
12 Correct 19 ms 5384 KB Output is correct
13 Correct 18 ms 5508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4428 KB Output is correct
2 Correct 4 ms 4428 KB Output is correct
3 Correct 3 ms 4360 KB Output is correct
4 Correct 3 ms 4428 KB Output is correct
5 Correct 5 ms 4428 KB Output is correct
6 Correct 200 ms 13664 KB Output is correct
7 Correct 232 ms 13764 KB Output is correct
8 Correct 264 ms 14048 KB Output is correct
9 Correct 278 ms 14604 KB Output is correct
10 Correct 218 ms 13768 KB Output is correct
11 Correct 211 ms 14528 KB Output is correct
12 Correct 189 ms 13424 KB Output is correct
13 Correct 209 ms 13640 KB Output is correct
14 Correct 234 ms 13868 KB Output is correct
15 Correct 296 ms 14024 KB Output is correct
16 Correct 184 ms 13532 KB Output is correct
17 Correct 199 ms 13708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4428 KB Output is correct
2 Correct 4 ms 4428 KB Output is correct
3 Correct 4 ms 4428 KB Output is correct
4 Correct 3 ms 4428 KB Output is correct
5 Correct 6 ms 4428 KB Output is correct
6 Correct 62 ms 8152 KB Output is correct
7 Correct 76 ms 9776 KB Output is correct
8 Correct 187 ms 14276 KB Output is correct
9 Correct 188 ms 14300 KB Output is correct
10 Correct 196 ms 14276 KB Output is correct
11 Correct 192 ms 14340 KB Output is correct
12 Correct 188 ms 14276 KB Output is correct
13 Correct 189 ms 14328 KB Output is correct
14 Correct 182 ms 14304 KB Output is correct
15 Correct 3 ms 4428 KB Output is correct
16 Correct 3 ms 4428 KB Output is correct
17 Correct 4 ms 4428 KB Output is correct
18 Correct 4 ms 4428 KB Output is correct
19 Correct 4 ms 4428 KB Output is correct
20 Correct 6 ms 4556 KB Output is correct
21 Correct 69 ms 9204 KB Output is correct
22 Correct 5 ms 4428 KB Output is correct
23 Correct 6 ms 4556 KB Output is correct
24 Correct 63 ms 9196 KB Output is correct
25 Correct 57 ms 9156 KB Output is correct
26 Correct 89 ms 9296 KB Output is correct
27 Correct 65 ms 9196 KB Output is correct
28 Correct 84 ms 10056 KB Output is correct
29 Correct 282 ms 15640 KB Output is correct
30 Correct 76 ms 9892 KB Output is correct
31 Correct 290 ms 15776 KB Output is correct
32 Correct 190 ms 15124 KB Output is correct
33 Correct 183 ms 15564 KB Output is correct
34 Correct 295 ms 15996 KB Output is correct
35 Correct 4 ms 4428 KB Output is correct
36 Correct 3 ms 4428 KB Output is correct
37 Correct 62 ms 8976 KB Output is correct
38 Correct 197 ms 14276 KB Output is correct
39 Correct 216 ms 14432 KB Output is correct
40 Correct 233 ms 14660 KB Output is correct
41 Correct 265 ms 15080 KB Output is correct
42 Correct 284 ms 15392 KB Output is correct
43 Correct 195 ms 14404 KB Output is correct
44 Correct 196 ms 14556 KB Output is correct
45 Correct 194 ms 14304 KB Output is correct
46 Correct 211 ms 14532 KB Output is correct
47 Correct 197 ms 14816 KB Output is correct
48 Correct 4 ms 4428 KB Output is correct
49 Correct 4 ms 4428 KB Output is correct
50 Correct 4 ms 4428 KB Output is correct
51 Correct 3 ms 4428 KB Output is correct
52 Correct 4 ms 4428 KB Output is correct
53 Correct 5 ms 4428 KB Output is correct
54 Correct 22 ms 5256 KB Output is correct
55 Correct 16 ms 5376 KB Output is correct
56 Correct 15 ms 5328 KB Output is correct
57 Correct 16 ms 5292 KB Output is correct
58 Correct 18 ms 5324 KB Output is correct
59 Correct 19 ms 5384 KB Output is correct
60 Correct 18 ms 5508 KB Output is correct
61 Correct 59 ms 8928 KB Output is correct
62 Correct 76 ms 9768 KB Output is correct
63 Correct 192 ms 14280 KB Output is correct
64 Correct 202 ms 14444 KB Output is correct
65 Correct 285 ms 14824 KB Output is correct
66 Correct 251 ms 15072 KB Output is correct
67 Correct 268 ms 15428 KB Output is correct
68 Correct 194 ms 14408 KB Output is correct
69 Correct 227 ms 15456 KB Output is correct
70 Correct 191 ms 14280 KB Output is correct
71 Correct 210 ms 14432 KB Output is correct
72 Correct 242 ms 14716 KB Output is correct
73 Correct 287 ms 14912 KB Output is correct
74 Correct 191 ms 14348 KB Output is correct
75 Correct 199 ms 14532 KB Output is correct