답안 #432534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
432534 2021-06-18T10:53:21 Z 2qbingxuan 말 (IOI15_horses) C++17
100 / 100
410 ms 52176 KB
#pragma GCC optimize("Ofast")
#include "horses.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(a...) qqbx(#a, a)
#define pary(a...) danb(#a, a)
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\e[1;32m(" << s << ") = ("), ..., (std::cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\e[0m\n";
}
#else
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)

using ld = long double;
using ll = long long;
using namespace std;
const int maxn = 500025;
const int mod = 1000000007;

struct Segtree {
    pair<ld,int> st[maxn * 2];
    ld lz[maxn];
    int n;
    void build(int N) {
        n = N;
        for (int i = n-1; i > 0; i--)
            st[i] = max(st[i<<1], st[i<<1|1]), lz[i] = 0;
    }
    void upd(int p, ld x) {
        st[p].first += x;
        if (p < n) lz[p] += x;
    }
    void pull(int p) {
        for (; p > 1; p>>=1) {
            st[p>>1] = max(st[p], st[p^1]);
            st[p>>1].first += lz[p>>1];
        }
    }
    void add(int l, int r, ld x) {
        int L = l, R = r;
        // push(l+n), push(r-1+n);
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l&1) upd(l++, x);
            if (r&1) upd(--r, x);
        }
        pull(L+n), pull(R-1+n);
    }
    int query() {
        return st[1].second;
        pair<ld,int> r;
        for (int i = 0; i < n; i++) {
            r = max(r, st[i + n]);
        }
        return r.second;
    }
} sgt;

ll modpow(ll e, ll p) {
    ll r = 1;
    while (p) {
        if (p&1) r = r*e%mod;
        e = e*e%mod;
        p >>= 1;
    }
    return r;
}
struct Fenwick {
    int n;
    ll b[maxn];
    void init(int N) {
        n = N;
        for (int i = 1; i <= n; i++) b[i] = 1;
    }
    void add(int p, ll d) {
        for (++p; p <= n; p += p&-p) b[p] = b[p] * d % mod;
    }
    ll query(int p) {
        ll r = 1;
        for (++p; p > 0; p -= p&-p) r = r * b[p] % mod;
        return r;
    }
} BIT;
int x[maxn], y[maxn], n;
int init(int N, int X[], int Y[]) {
    long double sum = 0;
    ll prod = 1;
    BIT.init(N);
    for (int i = 0; i < N; i++) {
        sum += log(X[i]);
        prod = prod * X[i] % mod;
        sgt.st[i + N] = { sum + log(Y[i]), i };
        BIT.add(i, X[i]);
    }
    sgt.build(N);
    n = N;
    for (int i = 0; i < N; i++) x[i] = X[i];
    for (int i = 0; i < N; i++) y[i] = Y[i];
    int p = sgt.query();
    return BIT.query(p) * y[p] % mod;
}

int updateX(int pos, int val) {	
    sgt.add(pos, n, -log(x[pos]));
    BIT.add(pos, modpow(x[pos], mod-2));
    x[pos] = val;
    sgt.add(pos, n, log(x[pos]));
    BIT.add(pos, x[pos]);
    int p = sgt.query();
    return BIT.query(p) * y[p] % mod;
}

int updateY(int pos, int val) {
    sgt.add(pos, pos+1, -log(y[pos]));
    y[pos] = val;
    sgt.add(pos, pos+1, log(y[pos]));
    int p = sgt.query();
    return BIT.query(p) * y[p] % mod;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:110:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  110 |     return BIT.query(p) * y[p] % mod;
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:120:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  120 |     return BIT.query(p) * y[p] % mod;
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:128:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  128 |     return BIT.query(p) * y[p] % mod;
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 31564 KB Output is correct
2 Correct 17 ms 31548 KB Output is correct
3 Correct 17 ms 31584 KB Output is correct
4 Correct 17 ms 31576 KB Output is correct
5 Correct 15 ms 31632 KB Output is correct
6 Correct 16 ms 31564 KB Output is correct
7 Correct 17 ms 31536 KB Output is correct
8 Correct 18 ms 31564 KB Output is correct
9 Correct 18 ms 31592 KB Output is correct
10 Correct 16 ms 31572 KB Output is correct
11 Correct 16 ms 31564 KB Output is correct
12 Correct 19 ms 31520 KB Output is correct
13 Correct 16 ms 31584 KB Output is correct
14 Correct 17 ms 31588 KB Output is correct
15 Correct 17 ms 31564 KB Output is correct
16 Correct 19 ms 31564 KB Output is correct
17 Correct 18 ms 31572 KB Output is correct
18 Correct 21 ms 31568 KB Output is correct
19 Correct 19 ms 31640 KB Output is correct
20 Correct 18 ms 31632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 31568 KB Output is correct
2 Correct 18 ms 31536 KB Output is correct
3 Correct 20 ms 31692 KB Output is correct
4 Correct 19 ms 31568 KB Output is correct
5 Correct 19 ms 31588 KB Output is correct
6 Correct 17 ms 31620 KB Output is correct
7 Correct 16 ms 31560 KB Output is correct
8 Correct 15 ms 31564 KB Output is correct
9 Correct 16 ms 31564 KB Output is correct
10 Correct 15 ms 31564 KB Output is correct
11 Correct 17 ms 31600 KB Output is correct
12 Correct 18 ms 31564 KB Output is correct
13 Correct 17 ms 31564 KB Output is correct
14 Correct 17 ms 31572 KB Output is correct
15 Correct 19 ms 31552 KB Output is correct
16 Correct 16 ms 31572 KB Output is correct
17 Correct 15 ms 31564 KB Output is correct
18 Correct 15 ms 31644 KB Output is correct
19 Correct 15 ms 31564 KB Output is correct
20 Correct 15 ms 31564 KB Output is correct
21 Correct 18 ms 31564 KB Output is correct
22 Correct 16 ms 31564 KB Output is correct
23 Correct 17 ms 31576 KB Output is correct
24 Correct 17 ms 31564 KB Output is correct
25 Correct 20 ms 31676 KB Output is correct
26 Correct 17 ms 31692 KB Output is correct
27 Correct 17 ms 31692 KB Output is correct
28 Correct 20 ms 31680 KB Output is correct
29 Correct 20 ms 31588 KB Output is correct
30 Correct 20 ms 31636 KB Output is correct
31 Correct 17 ms 31572 KB Output is correct
32 Correct 17 ms 31600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 52120 KB Output is correct
2 Correct 387 ms 52128 KB Output is correct
3 Correct 358 ms 52112 KB Output is correct
4 Correct 405 ms 52076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 31564 KB Output is correct
2 Correct 17 ms 31564 KB Output is correct
3 Correct 17 ms 31600 KB Output is correct
4 Correct 15 ms 31636 KB Output is correct
5 Correct 18 ms 31548 KB Output is correct
6 Correct 17 ms 31520 KB Output is correct
7 Correct 15 ms 31564 KB Output is correct
8 Correct 19 ms 31572 KB Output is correct
9 Correct 16 ms 31548 KB Output is correct
10 Correct 16 ms 31560 KB Output is correct
11 Correct 17 ms 31564 KB Output is correct
12 Correct 16 ms 31564 KB Output is correct
13 Correct 16 ms 31556 KB Output is correct
14 Correct 18 ms 31552 KB Output is correct
15 Correct 16 ms 31600 KB Output is correct
16 Correct 15 ms 31640 KB Output is correct
17 Correct 15 ms 31564 KB Output is correct
18 Correct 15 ms 31564 KB Output is correct
19 Correct 17 ms 31564 KB Output is correct
20 Correct 17 ms 31592 KB Output is correct
21 Correct 16 ms 31556 KB Output is correct
22 Correct 15 ms 31592 KB Output is correct
23 Correct 16 ms 31564 KB Output is correct
24 Correct 16 ms 31564 KB Output is correct
25 Correct 19 ms 31564 KB Output is correct
26 Correct 16 ms 31688 KB Output is correct
27 Correct 15 ms 31692 KB Output is correct
28 Correct 18 ms 31564 KB Output is correct
29 Correct 17 ms 31564 KB Output is correct
30 Correct 18 ms 31632 KB Output is correct
31 Correct 17 ms 31644 KB Output is correct
32 Correct 18 ms 31564 KB Output is correct
33 Correct 119 ms 51216 KB Output is correct
34 Correct 111 ms 51260 KB Output is correct
35 Correct 125 ms 51148 KB Output is correct
36 Correct 125 ms 51268 KB Output is correct
37 Correct 95 ms 51220 KB Output is correct
38 Correct 109 ms 51184 KB Output is correct
39 Correct 83 ms 51076 KB Output is correct
40 Correct 111 ms 51352 KB Output is correct
41 Correct 76 ms 51220 KB Output is correct
42 Correct 78 ms 51244 KB Output is correct
43 Correct 109 ms 51128 KB Output is correct
44 Correct 92 ms 51084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31564 KB Output is correct
2 Correct 16 ms 31564 KB Output is correct
3 Correct 16 ms 31524 KB Output is correct
4 Correct 17 ms 31636 KB Output is correct
5 Correct 19 ms 31504 KB Output is correct
6 Correct 16 ms 31632 KB Output is correct
7 Correct 16 ms 31528 KB Output is correct
8 Correct 17 ms 31632 KB Output is correct
9 Correct 16 ms 31564 KB Output is correct
10 Correct 19 ms 31572 KB Output is correct
11 Correct 16 ms 31552 KB Output is correct
12 Correct 16 ms 31588 KB Output is correct
13 Correct 16 ms 31564 KB Output is correct
14 Correct 19 ms 31564 KB Output is correct
15 Correct 17 ms 31636 KB Output is correct
16 Correct 17 ms 31616 KB Output is correct
17 Correct 17 ms 31644 KB Output is correct
18 Correct 17 ms 31564 KB Output is correct
19 Correct 19 ms 31628 KB Output is correct
20 Correct 17 ms 31564 KB Output is correct
21 Correct 18 ms 31588 KB Output is correct
22 Correct 17 ms 31540 KB Output is correct
23 Correct 18 ms 31564 KB Output is correct
24 Correct 21 ms 31580 KB Output is correct
25 Correct 20 ms 31596 KB Output is correct
26 Correct 17 ms 31564 KB Output is correct
27 Correct 20 ms 31640 KB Output is correct
28 Correct 18 ms 31564 KB Output is correct
29 Correct 18 ms 31564 KB Output is correct
30 Correct 17 ms 31652 KB Output is correct
31 Correct 18 ms 31564 KB Output is correct
32 Correct 18 ms 31692 KB Output is correct
33 Correct 187 ms 52112 KB Output is correct
34 Correct 383 ms 52144 KB Output is correct
35 Correct 401 ms 52080 KB Output is correct
36 Correct 410 ms 52040 KB Output is correct
37 Correct 117 ms 51320 KB Output is correct
38 Correct 114 ms 51236 KB Output is correct
39 Correct 125 ms 51164 KB Output is correct
40 Correct 126 ms 51340 KB Output is correct
41 Correct 93 ms 51272 KB Output is correct
42 Correct 97 ms 51148 KB Output is correct
43 Correct 81 ms 51192 KB Output is correct
44 Correct 110 ms 51216 KB Output is correct
45 Correct 76 ms 51264 KB Output is correct
46 Correct 80 ms 51268 KB Output is correct
47 Correct 94 ms 51096 KB Output is correct
48 Correct 93 ms 51088 KB Output is correct
49 Correct 349 ms 52104 KB Output is correct
50 Correct 380 ms 52168 KB Output is correct
51 Correct 238 ms 52060 KB Output is correct
52 Correct 295 ms 52140 KB Output is correct
53 Correct 323 ms 52164 KB Output is correct
54 Correct 287 ms 52120 KB Output is correct
55 Correct 231 ms 51396 KB Output is correct
56 Correct 271 ms 52176 KB Output is correct
57 Correct 171 ms 52112 KB Output is correct
58 Correct 194 ms 52160 KB Output is correct
59 Correct 105 ms 51096 KB Output is correct