답안 #747498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747498 2023-05-24T08:30:05 Z Desh03 말 (IOI15_horses) C++17
100 / 100
262 ms 39068 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

const int mod = 1000000007;
vector<int> x, y;
int n;

struct segtree1 {
    vector<double> st, lz;
    vector<int> id;
    int sz;
    void init(const vector<double> &a) {
        sz = a.size();
        while (sz & sz - 1) ++sz;
        st.resize(sz << 1), lz.resize(sz << 1), id.resize(sz << 1);
        for (int i = 0; i < a.size(); i++) st[i + sz] = a[i] + log2(y[i]), id[i + sz] = i;
        for (int i = sz - 1; i; i--) pull(i);
    }
    void pull(int v) {
        if (st[v << 1] >= st[v << 1 | 1]) st[v] = st[v << 1], id[v] = id[v << 1];
        else st[v] = st[v << 1 | 1], id[v] = id[v << 1 | 1];
    }
    void push(int v) {
        st[v << 1] += lz[v];
        st[v << 1 | 1] += lz[v];
        lz[v << 1] += lz[v];
        lz[v << 1 | 1] += lz[v];
        lz[v] = 0;
    }
    void updx(int v, int l, int r, int ql, int qr, double x) {
        if (l > qr || r < ql) return;
        if (l >= ql && r <= qr) {
            st[v] += x, lz[v] += x;
            return;
        }
        if (lz[v] != 0) push(v);
        int m = l + r >> 1;
        updx(v << 1, l, m, ql, qr, x);
        updx(v << 1 | 1, m + 1, r, ql, qr, x);
        pull(v);
    }
    void updy(int v, int l, int r, int u, double y) {
        if (l == r) {
            st[v] += y;
            return;
        }
        if (lz[v] != 0) push(v);
        int m = l + r >> 1;
        if (u <= m) updy(v << 1, l, m, u, y);
        else updy(v << 1 | 1, m + 1, r, u, y);
        pull(v);
    }
    void updx(int l, int r, double x) {
        updx(1, 0, sz - 1, l, r, x);
    }
    void updy(int u, double y) {
        updy(1, 0, sz - 1, u, y);
    }
} st1;

struct segtree2 {
    vector<int> st;
    int sz;
    void init(int n) {
        sz = n;
        st.resize(sz << 1);
    }
    void upd(int id, int x) {
        for (st[id += sz] = x; id >>= 1;) st[id] = 1LL * st[id << 1] * st[id << 1 | 1] % mod;
    }
    int qry(int l, int r) {
        int s = 1;
        for (l += sz, r += sz + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) s = 1LL * s * st[l++] % mod;
            if (r & 1) s = 1LL * s * st[--r] % mod;
        }
        return s;
    }
} st2;

int init(int N, int X[], int Y[]) {
    n = N, x.resize(n), y.resize(n);
    for (int i = 0; i < n; i++) x[i] = X[i], y[i] = Y[i];
    vector<double> p(n);
    p[0] = log2(x[0]);
    for (int i = 1; i < n; i++) p[i] = p[i - 1] + log2(x[i]);
    st1.init(p), st2.init(n);
    for (int i = 0; i < n; i++) st2.upd(i, x[i]);
    return 1LL * st2.qry(0, st1.id[1]) * y[st1.id[1]] % mod;
}

int updateX(int pos, int val) {
    st1.updx(pos, n - 1, log2(val) - log2(x[pos]));
    st2.upd(pos, val);
    x[pos] = val;
    return 1LL * st2.qry(0, st1.id[1]) * y[st1.id[1]] % mod;
}

int updateY(int pos, int val) {
    st1.updy(pos, log2(val) - log2(y[pos]));
    y[pos] = val;
    return 1LL * st2.qry(0, st1.id[1]) * y[st1.id[1]] % mod;
}

Compilation message

horses.cpp: In member function 'void segtree1::init(const std::vector<double>&)':
horses.cpp:14:20: warning: conversion from 'std::vector<double>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   14 |         sz = a.size();
      |              ~~~~~~^~
horses.cpp:15:24: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |         while (sz & sz - 1) ++sz;
      |                     ~~~^~~
horses.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for (int i = 0; i < a.size(); i++) st[i + sz] = a[i] + log2(y[i]), id[i + sz] = i;
      |                         ~~^~~~~~~~~~
horses.cpp: In member function 'void segtree1::updx(int, int, int, int, int, double)':
horses.cpp:31:59: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   31 |     void updx(int v, int l, int r, int ql, int qr, double x) {
      |                                                    ~~~~~~~^
horses.cpp:6:13: note: shadowed declaration is here
    6 | vector<int> x, y;
      |             ^
horses.cpp:38:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |         int m = l + r >> 1;
      |                 ~~^~~
horses.cpp: In member function 'void segtree1::updy(int, int, int, int, double)':
horses.cpp:43:50: warning: declaration of 'y' shadows a global declaration [-Wshadow]
   43 |     void updy(int v, int l, int r, int u, double y) {
      |                                           ~~~~~~~^
horses.cpp:6:16: note: shadowed declaration is here
    6 | vector<int> x, y;
      |                ^
horses.cpp:49:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |         int m = l + r >> 1;
      |                 ~~^~~
horses.cpp: In member function 'void segtree1::updx(int, int, double)':
horses.cpp:54:36: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   54 |     void updx(int l, int r, double x) {
      |                             ~~~~~~~^
horses.cpp:6:13: note: shadowed declaration is here
    6 | vector<int> x, y;
      |             ^
horses.cpp: In member function 'void segtree1::updy(int, double)':
horses.cpp:57:29: warning: declaration of 'y' shadows a global declaration [-Wshadow]
   57 |     void updy(int u, double y) {
      |                      ~~~~~~~^
horses.cpp:6:16: note: shadowed declaration is here
    6 | vector<int> x, y;
      |                ^
horses.cpp: In member function 'void segtree2::init(int)':
horses.cpp:65:19: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   65 |     void init(int n) {
      |               ~~~~^
horses.cpp:7:5: note: shadowed declaration is here
    7 | int n;
      |     ^
horses.cpp: In member function 'void segtree2::upd(int, int)':
horses.cpp:69:26: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   69 |     void upd(int id, int x) {
      |                      ~~~~^
horses.cpp:6:13: note: shadowed declaration is here
    6 | vector<int> x, y;
      |             ^
horses.cpp:70:88: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   70 |         for (st[id += sz] = x; id >>= 1;) st[id] = 1LL * st[id << 1] * st[id << 1 | 1] % mod;
      |                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In member function 'int segtree2::qry(int, int)':
horses.cpp:75:46: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   75 |             if (l & 1) s = 1LL * s * st[l++] % mod;
      |                            ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:76:46: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   76 |             if (r & 1) s = 1LL * s * st[--r] % mod;
      |                            ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:90:55: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   90 |     return 1LL * st2.qry(0, st1.id[1]) * y[st1.id[1]] % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:97:55: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   97 |     return 1LL * st2.qry(0, st1.id[1]) * y[st1.id[1]] % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:103:55: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |     return 1LL * st2.qry(0, st1.id[1]) * y[st1.id[1]] % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 37216 KB Output is correct
2 Correct 233 ms 38348 KB Output is correct
3 Correct 218 ms 37420 KB Output is correct
4 Correct 262 ms 37824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 296 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 388 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 360 KB Output is correct
33 Correct 119 ms 38116 KB Output is correct
34 Correct 120 ms 38096 KB Output is correct
35 Correct 155 ms 38440 KB Output is correct
36 Correct 145 ms 38484 KB Output is correct
37 Correct 105 ms 37828 KB Output is correct
38 Correct 112 ms 37916 KB Output is correct
39 Correct 102 ms 37848 KB Output is correct
40 Correct 116 ms 38240 KB Output is correct
41 Correct 92 ms 37708 KB Output is correct
42 Correct 95 ms 37828 KB Output is correct
43 Correct 108 ms 38320 KB Output is correct
44 Correct 110 ms 38988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 138 ms 37212 KB Output is correct
34 Correct 230 ms 38208 KB Output is correct
35 Correct 199 ms 37172 KB Output is correct
36 Correct 248 ms 38408 KB Output is correct
37 Correct 114 ms 38004 KB Output is correct
38 Correct 115 ms 37932 KB Output is correct
39 Correct 132 ms 38388 KB Output is correct
40 Correct 136 ms 38436 KB Output is correct
41 Correct 105 ms 37852 KB Output is correct
42 Correct 107 ms 37972 KB Output is correct
43 Correct 93 ms 37760 KB Output is correct
44 Correct 112 ms 38200 KB Output is correct
45 Correct 93 ms 37768 KB Output is correct
46 Correct 95 ms 37928 KB Output is correct
47 Correct 110 ms 38308 KB Output is correct
48 Correct 110 ms 39068 KB Output is correct
49 Correct 212 ms 38848 KB Output is correct
50 Correct 237 ms 38764 KB Output is correct
51 Correct 182 ms 39016 KB Output is correct
52 Correct 185 ms 39044 KB Output is correct
53 Correct 204 ms 38192 KB Output is correct
54 Correct 188 ms 38328 KB Output is correct
55 Correct 159 ms 37972 KB Output is correct
56 Correct 192 ms 38656 KB Output is correct
57 Correct 127 ms 38116 KB Output is correct
58 Correct 140 ms 38092 KB Output is correct
59 Correct 107 ms 38732 KB Output is correct