Submission #951132

# Submission time Handle Problem Language Result Execution time Memory
951132 2024-03-21T07:48:02 Z Trisanu_Das Comparing Plants (IOI20_plants) C++17
100 / 100
212 ms 16212 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;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 42 ms 11892 KB Output is correct
7 Correct 59 ms 13264 KB Output is correct
8 Correct 147 ms 15084 KB Output is correct
9 Correct 151 ms 15184 KB Output is correct
10 Correct 155 ms 15372 KB Output is correct
11 Correct 158 ms 15204 KB Output is correct
12 Correct 146 ms 15120 KB Output is correct
13 Correct 149 ms 15120 KB Output is correct
14 Correct 160 ms 15228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8076 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 53 ms 11012 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 46 ms 11036 KB Output is correct
11 Correct 43 ms 10892 KB Output is correct
12 Correct 43 ms 11280 KB Output is correct
13 Correct 46 ms 11092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 3 ms 8076 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 53 ms 11012 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 46 ms 11036 KB Output is correct
11 Correct 43 ms 10892 KB Output is correct
12 Correct 43 ms 11280 KB Output is correct
13 Correct 46 ms 11092 KB Output is correct
14 Correct 60 ms 11348 KB Output is correct
15 Correct 212 ms 12364 KB Output is correct
16 Correct 59 ms 11600 KB Output is correct
17 Correct 202 ms 12116 KB Output is correct
18 Correct 155 ms 12292 KB Output is correct
19 Correct 146 ms 12372 KB Output is correct
20 Correct 211 ms 12112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 43 ms 11008 KB Output is correct
4 Correct 151 ms 12112 KB Output is correct
5 Correct 158 ms 12364 KB Output is correct
6 Correct 177 ms 12200 KB Output is correct
7 Correct 187 ms 12112 KB Output is correct
8 Correct 210 ms 12368 KB Output is correct
9 Correct 161 ms 12364 KB Output is correct
10 Correct 147 ms 12364 KB Output is correct
11 Correct 146 ms 12196 KB Output is correct
12 Correct 145 ms 12284 KB Output is correct
13 Correct 148 ms 12284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 4 ms 8280 KB Output is correct
7 Correct 11 ms 9052 KB Output is correct
8 Correct 12 ms 9048 KB Output is correct
9 Correct 12 ms 9052 KB Output is correct
10 Correct 12 ms 9048 KB Output is correct
11 Correct 12 ms 9052 KB Output is correct
12 Correct 13 ms 9052 KB Output is correct
13 Correct 11 ms 9048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8024 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 153 ms 14564 KB Output is correct
7 Correct 189 ms 14696 KB Output is correct
8 Correct 189 ms 14956 KB Output is correct
9 Correct 200 ms 15176 KB Output is correct
10 Correct 149 ms 14416 KB Output is correct
11 Correct 162 ms 14928 KB Output is correct
12 Correct 160 ms 14200 KB Output is correct
13 Correct 156 ms 14592 KB Output is correct
14 Correct 173 ms 14616 KB Output is correct
15 Correct 187 ms 14840 KB Output is correct
16 Correct 145 ms 14420 KB Output is correct
17 Correct 155 ms 14576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 42 ms 11892 KB Output is correct
7 Correct 59 ms 13264 KB Output is correct
8 Correct 147 ms 15084 KB Output is correct
9 Correct 151 ms 15184 KB Output is correct
10 Correct 155 ms 15372 KB Output is correct
11 Correct 158 ms 15204 KB Output is correct
12 Correct 146 ms 15120 KB Output is correct
13 Correct 149 ms 15120 KB Output is correct
14 Correct 160 ms 15228 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8076 KB Output is correct
19 Correct 3 ms 8284 KB Output is correct
20 Correct 4 ms 8284 KB Output is correct
21 Correct 53 ms 11012 KB Output is correct
22 Correct 4 ms 8284 KB Output is correct
23 Correct 4 ms 8284 KB Output is correct
24 Correct 46 ms 11036 KB Output is correct
25 Correct 43 ms 10892 KB Output is correct
26 Correct 43 ms 11280 KB Output is correct
27 Correct 46 ms 11092 KB Output is correct
28 Correct 60 ms 11348 KB Output is correct
29 Correct 212 ms 12364 KB Output is correct
30 Correct 59 ms 11600 KB Output is correct
31 Correct 202 ms 12116 KB Output is correct
32 Correct 155 ms 12292 KB Output is correct
33 Correct 146 ms 12372 KB Output is correct
34 Correct 211 ms 12112 KB Output is correct
35 Correct 2 ms 8284 KB Output is correct
36 Correct 2 ms 8028 KB Output is correct
37 Correct 43 ms 11008 KB Output is correct
38 Correct 151 ms 12112 KB Output is correct
39 Correct 158 ms 12364 KB Output is correct
40 Correct 177 ms 12200 KB Output is correct
41 Correct 187 ms 12112 KB Output is correct
42 Correct 210 ms 12368 KB Output is correct
43 Correct 161 ms 12364 KB Output is correct
44 Correct 147 ms 12364 KB Output is correct
45 Correct 146 ms 12196 KB Output is correct
46 Correct 145 ms 12284 KB Output is correct
47 Correct 148 ms 12284 KB Output is correct
48 Correct 3 ms 8280 KB Output is correct
49 Correct 2 ms 8284 KB Output is correct
50 Correct 2 ms 8284 KB Output is correct
51 Correct 4 ms 8284 KB Output is correct
52 Correct 3 ms 8284 KB Output is correct
53 Correct 4 ms 8280 KB Output is correct
54 Correct 11 ms 9052 KB Output is correct
55 Correct 12 ms 9048 KB Output is correct
56 Correct 12 ms 9052 KB Output is correct
57 Correct 12 ms 9048 KB Output is correct
58 Correct 12 ms 9052 KB Output is correct
59 Correct 13 ms 9052 KB Output is correct
60 Correct 11 ms 9048 KB Output is correct
61 Correct 41 ms 12628 KB Output is correct
62 Correct 52 ms 13236 KB Output is correct
63 Correct 162 ms 15184 KB Output is correct
64 Correct 156 ms 15460 KB Output is correct
65 Correct 174 ms 15480 KB Output is correct
66 Correct 199 ms 15956 KB Output is correct
67 Correct 201 ms 16212 KB Output is correct
68 Correct 150 ms 15324 KB Output is correct
69 Correct 162 ms 15956 KB Output is correct
70 Correct 148 ms 15188 KB Output is correct
71 Correct 158 ms 15284 KB Output is correct
72 Correct 178 ms 15652 KB Output is correct
73 Correct 200 ms 15676 KB Output is correct
74 Correct 147 ms 15184 KB Output is correct
75 Correct 155 ms 15700 KB Output is correct