답안 #308347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308347 2020-10-01T00:52:36 Z bruce_test 식물 비교 (IOI20_plants) C++14
75 / 100
1359 ms 17772 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]; 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);
        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) upd(0, N-1, pos+N-K, N-1, -1, 1);
    }
//    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 7 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 69 ms 12536 KB Output is correct
7 Correct 130 ms 13016 KB Output is correct
8 Correct 647 ms 17640 KB Output is correct
9 Correct 650 ms 17640 KB Output is correct
10 Correct 647 ms 17640 KB Output is correct
11 Correct 633 ms 17512 KB Output is correct
12 Correct 632 ms 17640 KB Output is correct
13 Correct 631 ms 17768 KB Output is correct
14 Correct 636 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 7 ms 9728 KB Output is correct
4 Correct 7 ms 9704 KB Output is correct
5 Correct 8 ms 9728 KB Output is correct
6 Correct 12 ms 9856 KB Output is correct
7 Correct 96 ms 12792 KB Output is correct
8 Correct 9 ms 9728 KB Output is correct
9 Correct 12 ms 9856 KB Output is correct
10 Correct 97 ms 12792 KB Output is correct
11 Correct 92 ms 12664 KB Output is correct
12 Correct 89 ms 12792 KB Output is correct
13 Correct 98 ms 12740 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 9704 KB Output is correct
5 Correct 8 ms 9728 KB Output is correct
6 Correct 12 ms 9856 KB Output is correct
7 Correct 96 ms 12792 KB Output is correct
8 Correct 9 ms 9728 KB Output is correct
9 Correct 12 ms 9856 KB Output is correct
10 Correct 97 ms 12792 KB Output is correct
11 Correct 92 ms 12664 KB Output is correct
12 Correct 89 ms 12792 KB Output is correct
13 Correct 98 ms 12740 KB Output is correct
14 Correct 169 ms 13116 KB Output is correct
15 Correct 1358 ms 17640 KB Output is correct
16 Correct 168 ms 13144 KB Output is correct
17 Correct 1347 ms 17512 KB Output is correct
18 Correct 847 ms 17640 KB Output is correct
19 Correct 858 ms 17640 KB Output is correct
20 Correct 1278 ms 17640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9760 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 82 ms 12664 KB Output is correct
4 Correct 707 ms 17676 KB Output is correct
5 Correct 817 ms 17768 KB Output is correct
6 Correct 1063 ms 17676 KB Output is correct
7 Correct 1270 ms 17640 KB Output is correct
8 Correct 1356 ms 17768 KB Output is correct
9 Correct 748 ms 17768 KB Output is correct
10 Correct 741 ms 17640 KB Output is correct
11 Correct 641 ms 17640 KB Output is correct
12 Correct 719 ms 17640 KB Output is correct
13 Correct 844 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 7 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 9 ms 9856 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 23 ms 10360 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 10368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 8 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 11 ms 9728 KB Output is correct
6 Correct 799 ms 17640 KB Output is correct
7 Correct 1040 ms 17768 KB Output is correct
8 Correct 1225 ms 17512 KB Output is correct
9 Correct 1330 ms 17640 KB Output is correct
10 Correct 722 ms 17512 KB Output is correct
11 Correct 983 ms 17512 KB Output is correct
12 Correct 692 ms 17768 KB Output is correct
13 Correct 793 ms 17768 KB Output is correct
14 Correct 1020 ms 17640 KB Output is correct
15 Correct 1214 ms 17772 KB Output is correct
16 Correct 705 ms 17512 KB Output is correct
17 Correct 783 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 7 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 69 ms 12536 KB Output is correct
7 Correct 130 ms 13016 KB Output is correct
8 Correct 647 ms 17640 KB Output is correct
9 Correct 650 ms 17640 KB Output is correct
10 Correct 647 ms 17640 KB Output is correct
11 Correct 633 ms 17512 KB Output is correct
12 Correct 632 ms 17640 KB Output is correct
13 Correct 631 ms 17768 KB Output is correct
14 Correct 636 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 7 ms 9728 KB Output is correct
18 Correct 7 ms 9704 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Correct 12 ms 9856 KB Output is correct
21 Correct 96 ms 12792 KB Output is correct
22 Correct 9 ms 9728 KB Output is correct
23 Correct 12 ms 9856 KB Output is correct
24 Correct 97 ms 12792 KB Output is correct
25 Correct 92 ms 12664 KB Output is correct
26 Correct 89 ms 12792 KB Output is correct
27 Correct 98 ms 12740 KB Output is correct
28 Correct 169 ms 13116 KB Output is correct
29 Correct 1358 ms 17640 KB Output is correct
30 Correct 168 ms 13144 KB Output is correct
31 Correct 1347 ms 17512 KB Output is correct
32 Correct 847 ms 17640 KB Output is correct
33 Correct 858 ms 17640 KB Output is correct
34 Correct 1278 ms 17640 KB Output is correct
35 Correct 7 ms 9760 KB Output is correct
36 Correct 7 ms 9728 KB Output is correct
37 Correct 82 ms 12664 KB Output is correct
38 Correct 707 ms 17676 KB Output is correct
39 Correct 817 ms 17768 KB Output is correct
40 Correct 1063 ms 17676 KB Output is correct
41 Correct 1270 ms 17640 KB Output is correct
42 Correct 1356 ms 17768 KB Output is correct
43 Correct 748 ms 17768 KB Output is correct
44 Correct 741 ms 17640 KB Output is correct
45 Correct 641 ms 17640 KB Output is correct
46 Correct 719 ms 17640 KB Output is correct
47 Correct 844 ms 17640 KB Output is correct
48 Correct 7 ms 9728 KB Output is correct
49 Correct 7 ms 9728 KB Output is correct
50 Correct 7 ms 9728 KB Output is correct
51 Correct 8 ms 9728 KB Output is correct
52 Correct 8 ms 9728 KB Output is correct
53 Correct 9 ms 9856 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 23 ms 10360 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 10368 KB Output is correct
61 Correct 80 ms 12596 KB Output is correct
62 Correct 134 ms 13016 KB Output is correct
63 Correct 724 ms 17716 KB Output is correct
64 Correct 812 ms 17768 KB Output is correct
65 Correct 1042 ms 17640 KB Output is correct
66 Correct 1243 ms 17640 KB Output is correct
67 Correct 1359 ms 17640 KB Output is correct
68 Correct 752 ms 17704 KB Output is correct
69 Incorrect 1024 ms 17576 KB Output isn't correct
70 Halted 0 ms 0 KB -