답안 #308350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308350 2020-10-01T00:54:35 Z bruce_test 식물 비교 (IOI20_plants) C++14
100 / 100
1424 ms 18408 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define lc (rt<<1)
#define rc (rt<<1|1)
#define pb push_back
#define cl(a, b) memset(a, b, sizeof(a))
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vii;
typedef vector<pii> viii;
const int inf = 0x3F3F3F3F;
const ll infl = 0x3F3F3F3F3F3F3F3FLL;
const int mod = 1e9 + 7, MM = 2e5+5;
int N, K, lz[6*MM], mi[6*MM], stk[MM], tp=-1; vi ord1, ord2;
void pushdn(int rt){
    mi[lc]+=lz[rt]; mi[rc]+=lz[rt];
    lz[lc]+=lz[rt]; lz[rc]+=lz[rt]; lz[rt]=0;
}
void upd(int L, int R, int l, int r, int val, int rt){
    if(r < L || l > R) return;
    if(l <= L && R <= r){ mi[rt]+=val; lz[rt]+=val; return; }
    if(lz[rt]) pushdn(rt);
    int mid = (L+R)/2;
    if(l <= mid) upd(L, mid, l, r, val, lc);
    if(r > mid) upd(mid+1, R, l, r, val, rc);
    mi[rt] = min(mi[lc], mi[rc]);
}
int qry(int L, int R, int rt){
    if(mi[rt] > 0) return -1;
    if(L==R) return L;
    if(lz[rt]) pushdn(rt);
    int mid = (L+R)/2;
    if(mi[lc] > 0) return qry(mid+1, R, rc);
    return qry(L, mid, lc);
}
vi solve(vi& r){
    vi ret(N); cl(lz, 0); cl(mi, 0);
    for(int i=0; i<N; i++)
        upd(0, N-1, i, i, r[i], 1);
    for(int i=0; i<N; i++){
        int pos = qry(0, N-1, 1);
        while(pos < 0 && tp >= 0){
            upd(0, N-1, stk[tp--], N-1, -1, 1);
            pos = qry(0, N-1, 1);
        }
        ret[pos] = i;
        upd(0, N-1, pos, pos, inf, 1);
        upd(0, N-1, pos-K+1, pos-1, -1, 1);
        if(pos-K+1<0) stk[++tp] = pos+N-K;
    }
//    for(int x: ret) cout << x << " ";
//    cout << endl;
    return ret;
}
void init(int k, vi r){
    r.insert(r.end(), r.begin(), r.end());
    N = r.size(); K = k;
    ord1 = solve(r);
    for(int &x: r) x = k-1-x;
    ord2 = solve(r);
}
int compare_plants(int x, int y){
    if(x > y) return -compare_plants(y, x);
    if(ord1[x] > ord1[y] || ord2[x+N/2] < ord2[y]) return -1;
    if(ord2[x] > ord2[y] || ord1[x+N/2] < ord1[y]) return 1;
    return 0;
}
//int main(){
//    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//    int k=3; vi a={0, 1, 1, 2};
//    init(k, a);
//    for(int i=0; i<a.size(); i++)
//        for(int j=i+1; j<a.size(); j++)
//            cout << i << " vs " << j << " = " << compare_plants(i, j) << endl;
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 8 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 68 ms 12536 KB Output is correct
7 Correct 131 ms 13016 KB Output is correct
8 Correct 666 ms 17640 KB Output is correct
9 Correct 678 ms 17592 KB Output is correct
10 Correct 642 ms 17512 KB Output is correct
11 Correct 651 ms 17512 KB Output is correct
12 Correct 854 ms 17640 KB Output is correct
13 Correct 643 ms 17640 KB Output is correct
14 Correct 645 ms 17640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 8 ms 9728 KB Output is correct
5 Correct 8 ms 9728 KB Output is correct
6 Correct 14 ms 9856 KB Output is correct
7 Correct 94 ms 12736 KB Output is correct
8 Correct 9 ms 9728 KB Output is correct
9 Correct 13 ms 9852 KB Output is correct
10 Correct 108 ms 12792 KB Output is correct
11 Correct 97 ms 12792 KB Output is correct
12 Correct 86 ms 12920 KB Output is correct
13 Correct 92 ms 12796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 8 ms 9728 KB Output is correct
5 Correct 8 ms 9728 KB Output is correct
6 Correct 14 ms 9856 KB Output is correct
7 Correct 94 ms 12736 KB Output is correct
8 Correct 9 ms 9728 KB Output is correct
9 Correct 13 ms 9852 KB Output is correct
10 Correct 108 ms 12792 KB Output is correct
11 Correct 97 ms 12792 KB Output is correct
12 Correct 86 ms 12920 KB Output is correct
13 Correct 92 ms 12796 KB Output is correct
14 Correct 172 ms 13144 KB Output is correct
15 Correct 1393 ms 17640 KB Output is correct
16 Correct 169 ms 13016 KB Output is correct
17 Correct 1424 ms 17712 KB Output is correct
18 Correct 820 ms 18024 KB Output is correct
19 Correct 833 ms 18408 KB Output is correct
20 Correct 1272 ms 17640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 79 ms 12664 KB Output is correct
4 Correct 706 ms 17580 KB Output is correct
5 Correct 825 ms 17640 KB Output is correct
6 Correct 1043 ms 17640 KB Output is correct
7 Correct 1242 ms 17640 KB Output is correct
8 Correct 1358 ms 17716 KB Output is correct
9 Correct 762 ms 17676 KB Output is correct
10 Correct 754 ms 17640 KB Output is correct
11 Correct 636 ms 17512 KB Output is correct
12 Correct 742 ms 17640 KB Output is correct
13 Correct 839 ms 18024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 8 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 8 ms 9728 KB Output is correct
6 Correct 9 ms 9728 KB Output is correct
7 Correct 22 ms 10368 KB Output is correct
8 Correct 23 ms 10368 KB Output is correct
9 Correct 22 ms 10368 KB Output is correct
10 Correct 22 ms 10368 KB Output is correct
11 Correct 22 ms 10368 KB Output is correct
12 Correct 22 ms 10368 KB Output is correct
13 Correct 23 ms 10360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 10 ms 9728 KB Output is correct
6 Correct 811 ms 17588 KB Output is correct
7 Correct 1050 ms 17640 KB Output is correct
8 Correct 1270 ms 17640 KB Output is correct
9 Correct 1363 ms 17640 KB Output is correct
10 Correct 741 ms 17640 KB Output is correct
11 Correct 978 ms 17896 KB Output is correct
12 Correct 693 ms 17640 KB Output is correct
13 Correct 804 ms 17640 KB Output is correct
14 Correct 1037 ms 17768 KB Output is correct
15 Correct 1252 ms 17712 KB Output is correct
16 Correct 709 ms 17768 KB Output is correct
17 Correct 802 ms 17640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 8 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 68 ms 12536 KB Output is correct
7 Correct 131 ms 13016 KB Output is correct
8 Correct 666 ms 17640 KB Output is correct
9 Correct 678 ms 17592 KB Output is correct
10 Correct 642 ms 17512 KB Output is correct
11 Correct 651 ms 17512 KB Output is correct
12 Correct 854 ms 17640 KB Output is correct
13 Correct 643 ms 17640 KB Output is correct
14 Correct 645 ms 17640 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 9 ms 9728 KB Output is correct
18 Correct 8 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Correct 14 ms 9856 KB Output is correct
21 Correct 94 ms 12736 KB Output is correct
22 Correct 9 ms 9728 KB Output is correct
23 Correct 13 ms 9852 KB Output is correct
24 Correct 108 ms 12792 KB Output is correct
25 Correct 97 ms 12792 KB Output is correct
26 Correct 86 ms 12920 KB Output is correct
27 Correct 92 ms 12796 KB Output is correct
28 Correct 172 ms 13144 KB Output is correct
29 Correct 1393 ms 17640 KB Output is correct
30 Correct 169 ms 13016 KB Output is correct
31 Correct 1424 ms 17712 KB Output is correct
32 Correct 820 ms 18024 KB Output is correct
33 Correct 833 ms 18408 KB Output is correct
34 Correct 1272 ms 17640 KB Output is correct
35 Correct 7 ms 9728 KB Output is correct
36 Correct 7 ms 9728 KB Output is correct
37 Correct 79 ms 12664 KB Output is correct
38 Correct 706 ms 17580 KB Output is correct
39 Correct 825 ms 17640 KB Output is correct
40 Correct 1043 ms 17640 KB Output is correct
41 Correct 1242 ms 17640 KB Output is correct
42 Correct 1358 ms 17716 KB Output is correct
43 Correct 762 ms 17676 KB Output is correct
44 Correct 754 ms 17640 KB Output is correct
45 Correct 636 ms 17512 KB Output is correct
46 Correct 742 ms 17640 KB Output is correct
47 Correct 839 ms 18024 KB Output is correct
48 Correct 7 ms 9728 KB Output is correct
49 Correct 7 ms 9728 KB Output is correct
50 Correct 8 ms 9728 KB Output is correct
51 Correct 7 ms 9728 KB Output is correct
52 Correct 8 ms 9728 KB Output is correct
53 Correct 9 ms 9728 KB Output is correct
54 Correct 22 ms 10368 KB Output is correct
55 Correct 23 ms 10368 KB Output is correct
56 Correct 22 ms 10368 KB Output is correct
57 Correct 22 ms 10368 KB Output is correct
58 Correct 22 ms 10368 KB Output is correct
59 Correct 22 ms 10368 KB Output is correct
60 Correct 23 ms 10360 KB Output is correct
61 Correct 78 ms 12536 KB Output is correct
62 Correct 135 ms 12892 KB Output is correct
63 Correct 712 ms 17512 KB Output is correct
64 Correct 823 ms 17768 KB Output is correct
65 Correct 1088 ms 17640 KB Output is correct
66 Correct 1274 ms 17584 KB Output is correct
67 Correct 1364 ms 17640 KB Output is correct
68 Correct 760 ms 17640 KB Output is correct
69 Correct 1004 ms 17896 KB Output is correct
70 Correct 709 ms 17640 KB Output is correct
71 Correct 815 ms 17640 KB Output is correct
72 Correct 1054 ms 17640 KB Output is correct
73 Correct 1259 ms 17640 KB Output is correct
74 Correct 729 ms 17640 KB Output is correct
75 Correct 808 ms 17640 KB Output is correct