Submission #1051068

# Submission time Handle Problem Language Result Execution time Memory
1051068 2024-08-09T19:11:55 Z ArthuroWich Horses (IOI15_horses) C++17
100 / 100
1020 ms 76012 KB
#include "horses.h"
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int x[500005], y[500005], segp[4*500005], segm[4*500005], mod = 1e9+7;
void buildp(int n, int l, int r) {
    if (l == r) {
        segp[n] = x[l];
    } else {
        int m = (l+r)/2;
        buildp(2*n, l, m);
        buildp(2*n+1, m+1, r);
        segp[n] = segp[2*n] * segp[2*n+1];
        segp[n] %= mod;
    }
}
void buildm(int n, int l, int r) {
    if (l == r) {
        segm[n] = y[l];
    } else {
        int m = (l+r)/2;
        buildm(2*n, l, m);
        buildm(2*n+1, m+1, r);
        segm[n] = max(segm[2*n], segm[2*n+1]);
    }
}
void updatep(int n, int l, int r, int i, int v) {
    if (l == r) {
        segp[n] = v;
    } else {
        int m = (l+r)/2;
        if (l <= i && i <= m) {
            updatep(2*n, l, m, i, v);
        } else {
            updatep(2*n+1, m+1, r, i, v);
        }
        segp[n] = segp[2*n] * segp[2*n+1];
        segp[n] %= mod;
    }
}
void updatem(int n, int l, int r, int i, int v) {
    if (l == r) {
        segm[n] = v;
    } else {
        int m = (l+r)/2;
        if (l <= i && i <= m) {
            updatem(2*n, l, m, i, v);
        } else {
            updatem(2*n+1, m+1, r, i, v);
        }
        segm[n] = max(segm[2*n], segm[2*n+1]);
    }
}
int queryp(int n, int l, int r, int a, int b) {
    if (b < l || r < a) {
        return 1;
    } else if (a <= l && r <= b) {
        return segp[n];
    } else {
        int m = (l+r)/2;
        return (queryp(2*n, l, m, a, b)*queryp(2*n+1, m+1, r, a, b))%mod;
    }
}
int querym(int n, int l, int r, int a, int b) {
    if (b < l || r < a) {
        return 0;
    } else if (a <= l && r <= b) {
        return segm[n];
    } else {
        int m = (l+r)/2;
        return max(querym(2*n, l, m, a, b), querym(2*n+1, m+1, r, a, b));
    }
}
int n;
set<pair<int, int>> segs;
int32_t calc() {
    int ind = 0, indl = 0, indr = 0, co = 0;
    auto j = segs.end();
    while(j != segs.begin()) {
        if (co > 63) {
            break;
        }
        co++;
        j--;
    }
    long double v = 0, a = 0, b = 0;
    bool f = 0;
    for (; j != segs.end(); j++) {
        auto [l, r] = *j;
        if (l == r) {
            a += log2l(x[l]);
            if (a+log2l(y[l]) > v) {
                f = 0;
                v = a+log2l(y[l]);
                ind = l;
            }
        } else {
            int mx = querym(1, 0, n-1, l, r);
            if (a+log2l(mx) > v) {
                v = a+log2l(mx);
                indl = l;
                indr = r;
                f = 1;
            }
        }
    
    }
    if (f) {
        return (queryp(1, 0, n-1, 0, indl)*querym(1, 0, n-1, indl, indr)) % mod;
    }
    return (queryp(1, 0, n-1, 0, ind)*y[ind]) % mod;
}
int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
    n = N;
    int l = -1, r = 0;
    for (int i = 0; i < n; i++) {
        x[i] = X[i];
        y[i] = Y[i];
        if (x[i] == 1) {
            if (l == -1) {
                l = i;
            } 
            r = i;
        } else {
            if (l != -1) {
                segs.insert({l, r});
            }
            l = -1;
            segs.insert({i, i});
        }
    }
    if (l != -1) {
        segs.insert({l, r});
    }
    buildp(1, 0, n-1);
    buildm(1, 0, n-1);
    return calc();
}
int32_t updateX(int32_t pos, int32_t val) {	
    if (x[pos] == 1 && val != 1) {
        auto i = segs.upper_bound({pos, INT_MAX});
        i--;
        auto [l, r] = *i;
        segs.erase({l, r});
        if (l != pos) {
            segs.insert({l, pos-1});
        }
        segs.insert({pos, pos});
        if (r != pos) {
            segs.insert({pos+1, r});
        }
    } else if (x[pos] != 1 && val == 1) {
        auto i = segs.find({pos, pos});
        set<pair<int, int>> todel;
        todel.insert({pos, pos});
        int ll = pos, rr = pos;
        if (pos != 0 && x[pos-1] == 1) {
            i--;
            auto [l, r] = *i;
            ll = l;
            todel.insert({l, r});
            i++;
        }
        if (pos != n-1 && x[pos+1] == 1) {
            i++;
            auto [l, r] = *i;
            rr = r;
            todel.insert({l, r});
        }
        for (auto c : todel) {
            segs.erase(c);
        }
        segs.insert({ll, rr});
    }
    x[pos] = val;
    updatep(1, 0, n-1, pos, val);
    return calc();
}
int32_t updateY(int32_t pos, int32_t val) {
    y[pos] = val;
    updatem(1, 0, n-1, pos, val);
    return calc();
}

Compilation message

horses.cpp: In function 'int32_t calc()':
horses.cpp:109:75: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
  109 |         return (queryp(1, 0, n-1, 0, indl)*querym(1, 0, n-1, indl, indr)) % mod;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:111:47: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
  111 |     return (queryp(1, 0, n-1, 0, ind)*y[ind]) % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:86:31: warning: unused variable 'b' [-Wunused-variable]
   86 |     long double v = 0, a = 0, b = 0;
      |                               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8616 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8596 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 9 ms 8692 KB Output is correct
24 Correct 7 ms 8540 KB Output is correct
25 Correct 6 ms 8744 KB Output is correct
26 Correct 7 ms 8540 KB Output is correct
27 Correct 8 ms 8676 KB Output is correct
28 Correct 7 ms 8736 KB Output is correct
29 Correct 3 ms 8540 KB Output is correct
30 Correct 9 ms 8740 KB Output is correct
31 Correct 4 ms 8540 KB Output is correct
32 Correct 7 ms 8672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 954 ms 67048 KB Output is correct
2 Correct 691 ms 76012 KB Output is correct
3 Correct 931 ms 67148 KB Output is correct
4 Correct 766 ms 70992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8616 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 8 ms 8540 KB Output is correct
24 Correct 9 ms 8536 KB Output is correct
25 Correct 6 ms 8540 KB Output is correct
26 Correct 6 ms 8748 KB Output is correct
27 Correct 8 ms 8540 KB Output is correct
28 Correct 7 ms 8732 KB Output is correct
29 Correct 2 ms 8628 KB Output is correct
30 Correct 9 ms 8736 KB Output is correct
31 Correct 3 ms 8540 KB Output is correct
32 Correct 6 ms 8668 KB Output is correct
33 Correct 113 ms 35360 KB Output is correct
34 Correct 86 ms 35452 KB Output is correct
35 Correct 182 ms 73300 KB Output is correct
36 Correct 180 ms 73260 KB Output is correct
37 Correct 109 ms 33616 KB Output is correct
38 Correct 167 ms 65360 KB Output is correct
39 Correct 25 ms 33116 KB Output is correct
40 Correct 197 ms 68320 KB Output is correct
41 Correct 39 ms 33104 KB Output is correct
42 Correct 72 ms 33360 KB Output is correct
43 Correct 111 ms 68692 KB Output is correct
44 Correct 119 ms 68692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 1 ms 8612 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8612 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8616 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8552 KB Output is correct
23 Correct 8 ms 8676 KB Output is correct
24 Correct 11 ms 8624 KB Output is correct
25 Correct 6 ms 8540 KB Output is correct
26 Correct 6 ms 8536 KB Output is correct
27 Correct 9 ms 8688 KB Output is correct
28 Correct 7 ms 8536 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 10 ms 8540 KB Output is correct
31 Correct 3 ms 8668 KB Output is correct
32 Correct 7 ms 8672 KB Output is correct
33 Correct 895 ms 67152 KB Output is correct
34 Correct 756 ms 75824 KB Output is correct
35 Correct 935 ms 67216 KB Output is correct
36 Correct 810 ms 70856 KB Output is correct
37 Correct 115 ms 35384 KB Output is correct
38 Correct 86 ms 35464 KB Output is correct
39 Correct 196 ms 73344 KB Output is correct
40 Correct 197 ms 73200 KB Output is correct
41 Correct 126 ms 33660 KB Output is correct
42 Correct 164 ms 65468 KB Output is correct
43 Correct 25 ms 33036 KB Output is correct
44 Correct 205 ms 68464 KB Output is correct
45 Correct 38 ms 33112 KB Output is correct
46 Correct 72 ms 33364 KB Output is correct
47 Correct 123 ms 68688 KB Output is correct
48 Correct 123 ms 68724 KB Output is correct
49 Correct 964 ms 40008 KB Output is correct
50 Correct 776 ms 39920 KB Output is correct
51 Correct 751 ms 75092 KB Output is correct
52 Correct 750 ms 74776 KB Output is correct
53 Correct 1004 ms 38228 KB Output is correct
54 Correct 782 ms 67212 KB Output is correct
55 Correct 135 ms 34308 KB Output is correct
56 Correct 1020 ms 70248 KB Output is correct
57 Correct 274 ms 34816 KB Output is correct
58 Correct 618 ms 35316 KB Output is correct
59 Correct 137 ms 68956 KB Output is correct