답안 #586829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586829 2022-06-30T17:57:23 Z InternetPerson10 말 (IOI15_horses) C++11
100 / 100
555 ms 81912 KB
#include "horses.h"
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll MOD = 1000000007;

vector<int> x, y;
set<int> nonOnes;

ll modpow(ll n, ll e = MOD - 2) {
    if(e == 0) return 1;
    ll g = modpow(n, e/2);
    g *= g;
    g %= MOD;
    if(e%2) {
        g *= n;
        g %= MOD;
    }
    return g;
}

struct SegTree {
    int lx, rx;
    int val = 0;
    SegTree *ls, *rs;
    SegTree(int l, int r) : lx(l), rx(r) {
        if(rx - lx != 1) {
            int mid = (lx + rx) / 2;
            ls = new SegTree(l, mid);
            rs = new SegTree(mid, r);
            val = max(ls->val, rs->val);
        }
        else {
            if(lx < (int)y.size()) val = y[lx];
        }
    }
    int getMax(int l, int r) {
        if(r <= lx || rx <= l) return 0;
        if(l <= lx && rx <= r) return val;
        return max(ls->getMax(l, r), rs->getMax(l, r));
    }
    int changeVal(int g) {
        if(g+1 <= lx || rx <= g) return val;
        if(g <= lx && rx <= g+1) return val = y[g];
        return val = max(ls->changeVal(g), rs->changeVal(g));
    }
};

ll prod = 1;
SegTree *st;

int recalc() {
    __int128 currProd = 1;
    auto it = nonOnes.end();
    int rightBorder = x.size();
    do {
        it--;
        int idx = *it;
        int val = x[idx];
        currProd *= val;
        if((currProd > 1000000001) || (it == nonOnes.begin())) {
            __int128 best = -1, base = (prod * modpow(currProd % MOD)) % MOD;
            auto it2 = nonOnes.end();
            do {
                it2--;
                best = max(best, currProd * st->getMax((*it2), rightBorder));
                rightBorder = (*it2);
                currProd /= x[(*it2)];
            } while(it2 != it);
            assert(currProd == 1);
            assert(best != -1);
            return (int)(((best % MOD) * (base % MOD)) % MOD);
        }
    } while(it != nonOnes.begin());
    assert(false);
}

int init(int n, int X[], int Y[]) {
    x.resize(n);
    y.resize(n);
    for(int i = 0; i < n; i++) {
        x[i] = X[i]; y[i] = Y[i];
    }
    // Process X
    nonOnes.insert(0);
    for(int i = 0; i < n; i++) {
        if(x[i] != 1) nonOnes.insert(i);
        prod *= x[i];
        prod %= MOD;
    }
    // Process Y
    int g = 1;
    while(g < n) g *= 2;
    st = new SegTree(0, g);
	return recalc();
}

int updateX(int pos, int val) {
    prod *= modpow(x[pos]);
    prod %= MOD;
    x[pos] = val;
    prod *= x[pos];
    prod %= MOD;
    if(pos) {
        nonOnes.erase(pos);
        if(val != 1) nonOnes.insert(pos);
    }
    return recalc();
}

int updateY(int pos, int val) {	
    y[pos] = val;
    st->changeVal(pos);
    return recalc();
}

Compilation message

horses.cpp: In function 'int recalc()':
horses.cpp:57:29: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   57 |     int rightBorder = x.size();
      |                       ~~~~~~^~
horses.cpp:64:64: warning: conversion from '__int128' to 'll' {aka 'long long int'} may change value [-Wconversion]
   64 |             __int128 best = -1, base = (prod * modpow(currProd % MOD)) % MOD;
      |                                                       ~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 555 ms 81816 KB Output is correct
2 Correct 410 ms 81816 KB Output is correct
3 Correct 401 ms 81912 KB Output is correct
4 Correct 417 ms 81820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 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 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 80 ms 57508 KB Output is correct
34 Correct 77 ms 57552 KB Output is correct
35 Correct 210 ms 80904 KB Output is correct
36 Correct 204 ms 80872 KB Output is correct
37 Correct 109 ms 57676 KB Output is correct
38 Correct 131 ms 69412 KB Output is correct
39 Correct 74 ms 57380 KB Output is correct
40 Correct 185 ms 81004 KB Output is correct
41 Correct 80 ms 57352 KB Output is correct
42 Correct 96 ms 57424 KB Output is correct
43 Correct 173 ms 80792 KB Output is correct
44 Correct 179 ms 80860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 502 ms 81848 KB Output is correct
34 Correct 424 ms 81804 KB Output is correct
35 Correct 373 ms 81824 KB Output is correct
36 Correct 426 ms 81772 KB Output is correct
37 Correct 77 ms 57548 KB Output is correct
38 Correct 77 ms 57564 KB Output is correct
39 Correct 209 ms 80844 KB Output is correct
40 Correct 209 ms 80908 KB Output is correct
41 Correct 105 ms 57472 KB Output is correct
42 Correct 125 ms 69324 KB Output is correct
43 Correct 68 ms 57288 KB Output is correct
44 Correct 188 ms 80912 KB Output is correct
45 Correct 83 ms 57548 KB Output is correct
46 Correct 91 ms 57412 KB Output is correct
47 Correct 187 ms 80828 KB Output is correct
48 Correct 177 ms 80868 KB Output is correct
49 Correct 242 ms 59472 KB Output is correct
50 Correct 220 ms 59424 KB Output is correct
51 Correct 344 ms 81868 KB Output is correct
52 Correct 280 ms 81740 KB Output is correct
53 Correct 540 ms 59312 KB Output is correct
54 Correct 289 ms 72396 KB Output is correct
55 Correct 155 ms 57560 KB Output is correct
56 Correct 300 ms 81868 KB Output is correct
57 Correct 306 ms 58316 KB Output is correct
58 Correct 443 ms 58308 KB Output is correct
59 Correct 170 ms 80864 KB Output is correct