답안 #31010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31010 2017-08-04T01:33:13 Z kajebiii 말 (IOI15_horses) C++14
100 / 100
366 ms 26432 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, double> pd;
typedef pair<int, int> pi;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF * 2;

const int MOD = 1e9 + 7;

int N, *X, *Y;
ll myMul(ll x, ll y) {
    if(x < MOD && y < MOD) return x*y;
    return LINF;
}
struct MUL{
    int P; vector<ll> val, mod;
    void merge(int i) {
        val[i] = myMul(val[i*2], val[i*2+1]);
        mod[i] = mod[i*2] * mod[i*2+1] % MOD;
    }
    MUL() {}
    MUL(int n, int nr[]) {
        for(P=1; P<n; P<<=1);
        val = mod = vector<ll>(2*P, 1ll);
        for(int i=0; i<n; i++) val[P+i] = mod[P+i] = nr[i];
        for(int i=P-1; i>=1; i--) merge(i);
    }
    void updateX(int v, int k) {
        X[v] = k;
        v += P;
        val[v] = mod[v] = k;
        while(v/=2) merge(v);
    }
    ll getMul(int a, int b) {
        ll res = 1;
        for(a+=P, b+=P; a<=b; a>>=1, b>>=1) {
            if(a%2==1) res = myMul(res, val[a++]);
            if(b%2==0) res = myMul(res, val[b--]);
        }
        return res;
    }
    ll getMod(int a, int b) {
        ll res = 1;
        for(a+=P, b+=P; a<=b; a>>=1, b>>=1) {
            if(a%2==1) res = res * mod[a++] % MOD;
            if(b%2==0) res = res * mod[b--] % MOD;
        }
        return res;
    }
}Mul;

struct IDX{
    int P; vector<int> ix;
    void merge(int i) {
        int l = ix[i*2], r = ix[i*2+1];
        int res = -1;
        if(r == -1) res = l;
        else{
            ll mul = Mul.getMul(l+1, r);
            if(mul >= MOD) res = r;
            else{
                if(Y[l] >= mul * Y[r]) res = l;
                else res = r;
            }
        }
        ix[i] = res;
    }
    IDX() {}
    IDX(int n, int nr[]) {
        for(P=1; P<n; P<<=1);
        ix = vector<int>(2*P, -1);
        for(int i=0; i<n; i++) ix[P+i] = i;
        for(int i=P-1; i>=1; i--) merge(i);
    }
    void updateX(int v, int k) {
        v += P;
        while(v/=2) merge(v);
    }
    void updateY(int v, int k) {
        Y[v] = k;
        v += P;
        while(v/=2) merge(v);
    }
    int getMax() {return ix[1];}
}Idx;
int getAns() {
    int ans = Idx.getMax();
    return Mul.getMod(0, ans) * Y[ans] % MOD;
}
int init(int n, int x[], int y[]) {
    N = n; X = x; Y = y;
    Mul = MUL(n, x);
    Idx = IDX(n, y);
	return getAns();
}

int updateX(int pos, int val) {	
    Mul.updateX(pos, val);
    Idx.updateX(pos, val);
	return getAns();
}

int updateY(int pos, int val) {
    Idx.updateY(pos, val);
	return getAns();
}

Compilation message

horses.cpp:81:23: warning: unused parameter 'nr' [-Wunused-parameter]
     IDX(int n, int nr[]) {
                       ^
horses.cpp:87:29: warning: unused parameter 'k' [-Wunused-parameter]
     void updateX(int v, int k) {
                             ^
horses.cpp: In function 'int getAns()':
horses.cpp:100:42: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
     return Mul.getMod(0, ans) * Y[ans] % MOD;
                                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Correct 0 ms 2028 KB Output is correct
6 Correct 0 ms 2028 KB Output is correct
7 Correct 0 ms 2028 KB Output is correct
8 Correct 0 ms 2028 KB Output is correct
9 Correct 0 ms 2028 KB Output is correct
10 Correct 0 ms 2028 KB Output is correct
11 Correct 0 ms 2028 KB Output is correct
12 Correct 0 ms 2028 KB Output is correct
13 Correct 0 ms 2028 KB Output is correct
14 Correct 0 ms 2028 KB Output is correct
15 Correct 0 ms 2028 KB Output is correct
16 Correct 0 ms 2028 KB Output is correct
17 Correct 0 ms 2028 KB Output is correct
18 Correct 0 ms 2028 KB Output is correct
19 Correct 0 ms 2028 KB Output is correct
20 Correct 0 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Correct 0 ms 2028 KB Output is correct
6 Correct 0 ms 2028 KB Output is correct
7 Correct 0 ms 2028 KB Output is correct
8 Correct 0 ms 2028 KB Output is correct
9 Correct 0 ms 2028 KB Output is correct
10 Correct 0 ms 2028 KB Output is correct
11 Correct 0 ms 2028 KB Output is correct
12 Correct 0 ms 2028 KB Output is correct
13 Correct 0 ms 2028 KB Output is correct
14 Correct 0 ms 2028 KB Output is correct
15 Correct 0 ms 2028 KB Output is correct
16 Correct 0 ms 2028 KB Output is correct
17 Correct 0 ms 2028 KB Output is correct
18 Correct 0 ms 2028 KB Output is correct
19 Correct 0 ms 2028 KB Output is correct
20 Correct 0 ms 2028 KB Output is correct
21 Correct 0 ms 2028 KB Output is correct
22 Correct 0 ms 2028 KB Output is correct
23 Correct 0 ms 2028 KB Output is correct
24 Correct 0 ms 2028 KB Output is correct
25 Correct 0 ms 2028 KB Output is correct
26 Correct 0 ms 2028 KB Output is correct
27 Correct 3 ms 2028 KB Output is correct
28 Correct 0 ms 2028 KB Output is correct
29 Correct 0 ms 2028 KB Output is correct
30 Correct 0 ms 2028 KB Output is correct
31 Correct 0 ms 2028 KB Output is correct
32 Correct 0 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 26432 KB Output is correct
2 Correct 266 ms 26432 KB Output is correct
3 Correct 276 ms 26432 KB Output is correct
4 Correct 253 ms 26432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Correct 0 ms 2028 KB Output is correct
6 Correct 0 ms 2028 KB Output is correct
7 Correct 0 ms 2028 KB Output is correct
8 Correct 0 ms 2028 KB Output is correct
9 Correct 0 ms 2028 KB Output is correct
10 Correct 0 ms 2028 KB Output is correct
11 Correct 0 ms 2028 KB Output is correct
12 Correct 0 ms 2028 KB Output is correct
13 Correct 0 ms 2028 KB Output is correct
14 Correct 0 ms 2028 KB Output is correct
15 Correct 0 ms 2028 KB Output is correct
16 Correct 0 ms 2028 KB Output is correct
17 Correct 0 ms 2028 KB Output is correct
18 Correct 0 ms 2028 KB Output is correct
19 Correct 0 ms 2028 KB Output is correct
20 Correct 0 ms 2028 KB Output is correct
21 Correct 0 ms 2028 KB Output is correct
22 Correct 0 ms 2028 KB Output is correct
23 Correct 0 ms 2028 KB Output is correct
24 Correct 0 ms 2028 KB Output is correct
25 Correct 0 ms 2028 KB Output is correct
26 Correct 0 ms 2028 KB Output is correct
27 Correct 0 ms 2028 KB Output is correct
28 Correct 0 ms 2028 KB Output is correct
29 Correct 0 ms 2028 KB Output is correct
30 Correct 0 ms 2028 KB Output is correct
31 Correct 0 ms 2028 KB Output is correct
32 Correct 0 ms 2028 KB Output is correct
33 Correct 73 ms 26432 KB Output is correct
34 Correct 69 ms 26432 KB Output is correct
35 Correct 59 ms 26432 KB Output is correct
36 Correct 66 ms 26432 KB Output is correct
37 Correct 69 ms 26432 KB Output is correct
38 Correct 36 ms 26432 KB Output is correct
39 Correct 33 ms 26432 KB Output is correct
40 Correct 66 ms 26432 KB Output is correct
41 Correct 36 ms 26432 KB Output is correct
42 Correct 26 ms 26432 KB Output is correct
43 Correct 26 ms 26432 KB Output is correct
44 Correct 43 ms 26432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Correct 0 ms 2028 KB Output is correct
6 Correct 0 ms 2028 KB Output is correct
7 Correct 0 ms 2028 KB Output is correct
8 Correct 0 ms 2028 KB Output is correct
9 Correct 0 ms 2028 KB Output is correct
10 Correct 0 ms 2028 KB Output is correct
11 Correct 0 ms 2028 KB Output is correct
12 Correct 0 ms 2028 KB Output is correct
13 Correct 0 ms 2028 KB Output is correct
14 Correct 0 ms 2028 KB Output is correct
15 Correct 0 ms 2028 KB Output is correct
16 Correct 0 ms 2028 KB Output is correct
17 Correct 0 ms 2028 KB Output is correct
18 Correct 0 ms 2028 KB Output is correct
19 Correct 0 ms 2028 KB Output is correct
20 Correct 0 ms 2028 KB Output is correct
21 Correct 0 ms 2028 KB Output is correct
22 Correct 0 ms 2028 KB Output is correct
23 Correct 0 ms 2028 KB Output is correct
24 Correct 0 ms 2028 KB Output is correct
25 Correct 0 ms 2028 KB Output is correct
26 Correct 0 ms 2028 KB Output is correct
27 Correct 0 ms 2028 KB Output is correct
28 Correct 0 ms 2028 KB Output is correct
29 Correct 0 ms 2028 KB Output is correct
30 Correct 0 ms 2028 KB Output is correct
31 Correct 0 ms 2028 KB Output is correct
32 Correct 0 ms 2028 KB Output is correct
33 Correct 53 ms 26432 KB Output is correct
34 Correct 169 ms 26432 KB Output is correct
35 Correct 176 ms 26432 KB Output is correct
36 Correct 246 ms 26432 KB Output is correct
37 Correct 73 ms 26432 KB Output is correct
38 Correct 69 ms 26432 KB Output is correct
39 Correct 59 ms 26432 KB Output is correct
40 Correct 56 ms 26432 KB Output is correct
41 Correct 59 ms 26432 KB Output is correct
42 Correct 46 ms 26432 KB Output is correct
43 Correct 49 ms 26432 KB Output is correct
44 Correct 49 ms 26432 KB Output is correct
45 Correct 36 ms 26432 KB Output is correct
46 Correct 26 ms 26432 KB Output is correct
47 Correct 39 ms 26432 KB Output is correct
48 Correct 43 ms 26432 KB Output is correct
49 Correct 343 ms 26432 KB Output is correct
50 Correct 366 ms 26432 KB Output is correct
51 Correct 103 ms 26432 KB Output is correct
52 Correct 129 ms 26432 KB Output is correct
53 Correct 299 ms 26432 KB Output is correct
54 Correct 109 ms 26432 KB Output is correct
55 Correct 143 ms 26432 KB Output is correct
56 Correct 179 ms 26432 KB Output is correct
57 Correct 156 ms 26432 KB Output is correct
58 Correct 146 ms 26432 KB Output is correct
59 Correct 43 ms 26432 KB Output is correct