Submission #304445

# Submission time Handle Problem Language Result Execution time Memory
304445 2020-09-21T11:13:45 Z mhy908 Comparing Plants (IOI20_plants) C++14
100 / 100
1885 ms 35280 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;
    }
    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
*/

# Verdict Execution time Memory 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 78 ms 28280 KB Output is correct
7 Correct 165 ms 28728 KB Output is correct
8 Correct 990 ms 34892 KB Output is correct
9 Correct 996 ms 34832 KB Output is correct
10 Correct 982 ms 34896 KB Output is correct
11 Correct 982 ms 34836 KB Output is correct
12 Correct 976 ms 34892 KB Output is correct
13 Correct 970 ms 34892 KB Output is correct
14 Correct 982 ms 34772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 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 20 ms 25344 KB Output is correct
6 Correct 23 ms 25472 KB Output is correct
7 Correct 110 ms 28408 KB Output is correct
8 Correct 20 ms 25472 KB Output is correct
9 Correct 24 ms 25472 KB Output is correct
10 Correct 110 ms 28408 KB Output is correct
11 Correct 101 ms 28280 KB Output is correct
12 Correct 106 ms 28536 KB Output is correct
13 Correct 137 ms 28488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 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 20 ms 25344 KB Output is correct
6 Correct 23 ms 25472 KB Output is correct
7 Correct 110 ms 28408 KB Output is correct
8 Correct 20 ms 25472 KB Output is correct
9 Correct 24 ms 25472 KB Output is correct
10 Correct 110 ms 28408 KB Output is correct
11 Correct 101 ms 28280 KB Output is correct
12 Correct 106 ms 28536 KB Output is correct
13 Correct 137 ms 28488 KB Output is correct
14 Correct 203 ms 28828 KB Output is correct
15 Correct 1885 ms 34892 KB Output is correct
16 Correct 198 ms 28728 KB Output is correct
17 Correct 1859 ms 34772 KB Output is correct
18 Correct 1173 ms 35276 KB Output is correct
19 Correct 1188 ms 35280 KB Output is correct
20 Correct 1695 ms 34832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 25464 KB Output is correct
2 Correct 18 ms 25344 KB Output is correct
3 Correct 91 ms 28280 KB Output is correct
4 Correct 1035 ms 34832 KB Output is correct
5 Correct 1126 ms 34892 KB Output is correct
6 Correct 1513 ms 34892 KB Output is correct
7 Correct 1749 ms 34892 KB Output is correct
8 Correct 1842 ms 34892 KB Output is correct
9 Correct 1096 ms 34776 KB Output is correct
10 Correct 1068 ms 34892 KB Output is correct
11 Correct 971 ms 34768 KB Output is correct
12 Correct 1091 ms 34776 KB Output is correct
13 Correct 1186 ms 35020 KB Output is correct
# Verdict Execution time Memory 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 20 ms 25472 KB Output is correct
7 Correct 32 ms 25984 KB Output is correct
8 Correct 33 ms 25976 KB Output is correct
9 Correct 33 ms 26104 KB Output is correct
10 Correct 33 ms 26104 KB Output is correct
11 Correct 33 ms 25976 KB Output is correct
12 Correct 33 ms 25984 KB Output is correct
13 Correct 39 ms 25984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 25344 KB Output is correct
2 Correct 19 ms 25368 KB Output is correct
3 Correct 18 ms 25344 KB Output is correct
4 Correct 18 ms 25344 KB Output is correct
5 Correct 21 ms 25344 KB Output is correct
6 Correct 1121 ms 34764 KB Output is correct
7 Correct 1457 ms 34900 KB Output is correct
8 Correct 1729 ms 34840 KB Output is correct
9 Correct 1838 ms 34780 KB Output is correct
10 Correct 1065 ms 34892 KB Output is correct
11 Correct 1378 ms 35080 KB Output is correct
12 Correct 1022 ms 34764 KB Output is correct
13 Correct 1122 ms 34892 KB Output is correct
14 Correct 1476 ms 34836 KB Output is correct
15 Correct 1757 ms 34892 KB Output is correct
16 Correct 1025 ms 34764 KB Output is correct
17 Correct 1110 ms 34892 KB Output is correct
# Verdict Execution time Memory 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 78 ms 28280 KB Output is correct
7 Correct 165 ms 28728 KB Output is correct
8 Correct 990 ms 34892 KB Output is correct
9 Correct 996 ms 34832 KB Output is correct
10 Correct 982 ms 34896 KB Output is correct
11 Correct 982 ms 34836 KB Output is correct
12 Correct 976 ms 34892 KB Output is correct
13 Correct 970 ms 34892 KB Output is correct
14 Correct 982 ms 34772 KB Output is correct
15 Correct 19 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 Correct 20 ms 25344 KB Output is correct
20 Correct 23 ms 25472 KB Output is correct
21 Correct 110 ms 28408 KB Output is correct
22 Correct 20 ms 25472 KB Output is correct
23 Correct 24 ms 25472 KB Output is correct
24 Correct 110 ms 28408 KB Output is correct
25 Correct 101 ms 28280 KB Output is correct
26 Correct 106 ms 28536 KB Output is correct
27 Correct 137 ms 28488 KB Output is correct
28 Correct 203 ms 28828 KB Output is correct
29 Correct 1885 ms 34892 KB Output is correct
30 Correct 198 ms 28728 KB Output is correct
31 Correct 1859 ms 34772 KB Output is correct
32 Correct 1173 ms 35276 KB Output is correct
33 Correct 1188 ms 35280 KB Output is correct
34 Correct 1695 ms 34832 KB Output is correct
35 Correct 19 ms 25464 KB Output is correct
36 Correct 18 ms 25344 KB Output is correct
37 Correct 91 ms 28280 KB Output is correct
38 Correct 1035 ms 34832 KB Output is correct
39 Correct 1126 ms 34892 KB Output is correct
40 Correct 1513 ms 34892 KB Output is correct
41 Correct 1749 ms 34892 KB Output is correct
42 Correct 1842 ms 34892 KB Output is correct
43 Correct 1096 ms 34776 KB Output is correct
44 Correct 1068 ms 34892 KB Output is correct
45 Correct 971 ms 34768 KB Output is correct
46 Correct 1091 ms 34776 KB Output is correct
47 Correct 1186 ms 35020 KB Output is correct
48 Correct 18 ms 25344 KB Output is correct
49 Correct 18 ms 25344 KB Output is correct
50 Correct 18 ms 25344 KB Output is correct
51 Correct 18 ms 25344 KB Output is correct
52 Correct 18 ms 25344 KB Output is correct
53 Correct 20 ms 25472 KB Output is correct
54 Correct 32 ms 25984 KB Output is correct
55 Correct 33 ms 25976 KB Output is correct
56 Correct 33 ms 26104 KB Output is correct
57 Correct 33 ms 26104 KB Output is correct
58 Correct 33 ms 25976 KB Output is correct
59 Correct 33 ms 25984 KB Output is correct
60 Correct 39 ms 25984 KB Output is correct
61 Correct 90 ms 28212 KB Output is correct
62 Correct 166 ms 28728 KB Output is correct
63 Correct 1045 ms 34896 KB Output is correct
64 Correct 1141 ms 34764 KB Output is correct
65 Correct 1481 ms 34892 KB Output is correct
66 Correct 1746 ms 34892 KB Output is correct
67 Correct 1877 ms 34892 KB Output is correct
68 Correct 1080 ms 34768 KB Output is correct
69 Correct 1366 ms 35148 KB Output is correct
70 Correct 1039 ms 34892 KB Output is correct
71 Correct 1131 ms 34764 KB Output is correct
72 Correct 1492 ms 34780 KB Output is correct
73 Correct 1765 ms 34892 KB Output is correct
74 Correct 1048 ms 34892 KB Output is correct
75 Correct 1118 ms 34764 KB Output is correct