답안 #174671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
174671 2020-01-06T16:01:04 Z mat_v 말 (IOI15_horses) C++14
100 / 100
522 ms 118032 KB
#include <bits/stdc++.h>
#include "horses.h"
#define mod 1000000007
#define maxn 500005
#define xx first
#define yy second
using namespace std;
typedef long long ll;
typedef pair<long double,ll>pdl;
ll add(ll x, ll y){
    return (x + y)%mod;
}
bool preso = 0;
ll mul(ll x, ll y){
    if(x * y >= mod)preso = 1;
    return (x * y)%mod;
}
ll power(ll x, ll y){
    if(y == 0)return 1;
    ll pola = power(x, y / 2);
    pola = mul(pola, pola);
    if(y%2 == 1)pola = mul(pola, x);
    return pola;
}
ll inverz(ll x){
    return power(x, mod - 2);
}


int n;
ll x[maxn];
ll y[maxn];
long double lgx[maxn];
long double lgy[maxn];
long double niz[maxn];
ll pro[4 * maxn];
///
struct cvor{
    long double lg;
    ll pref;
    int poz;
    long double lazylg;
    ll lazy;
}seg[4 * maxn];
void seginit(int node, int l, int r){
    seg[node].lazy = 1;
    if(l == r){
        seg[node].lg = niz[l];
        seg[node].poz = l;
        seg[node].pref = pro[l];
        return;
    }
    int mid = (l + r) / 2;
    seginit(node * 2, l, mid);
    seginit(node * 2 + 1, mid + 1, r);
    if(seg[node * 2].lg > seg[node * 2 + 1].lg)seg[node].pref = seg[node * 2].pref;
    else seg[node].pref = seg[node * 2 + 1].pref;
    seg[node].lg = max(seg[node * 2].lg, seg[node * 2 + 1].lg);
}

void propagate(int node, int l, int r){
    seg[node].lg += seg[node].lazylg;
    seg[node].pref = mul(seg[node].pref, seg[node].lazy);
    if(l != r){
        seg[node * 2].lazylg += seg[node].lazylg;
        seg[node * 2 + 1].lazylg += seg[node].lazylg;
        seg[node * 2].lazy = mul(seg[node * 2].lazy, seg[node].lazy);
        seg[node * 2 + 1].lazy = mul(seg[node * 2 + 1].lazy, seg[node].lazy);
    }
    seg[node].lazylg = 0;
    seg[node].lazy = 1;
}
void update(int node, int l, int r, int levo, int desno, long double lgval, ll val){
    propagate(node, l, r);
    if(r < levo || desno < l)return;
    if(r <= desno && l >= levo){
        seg[node].lazylg += lgval;
        seg[node].lazy = mul(seg[node].lazy, val);
        propagate(node, l, r);
        return;
    }
    int mid = (l + r) / 2;
    update(node * 2, l, mid, levo, desno, lgval, val);
    update(node * 2 + 1, mid + 1, r, levo, desno, lgval, val);
    if(seg[node * 2].lg > seg[node * 2 + 1].lg)seg[node].pref = seg[node * 2].pref;
    else seg[node].pref = seg[node * 2 + 1].pref;
    seg[node].lg = max(seg[node * 2].lg, seg[node * 2 + 1].lg);
}
pdl query(int node, int l, int r, int levo, int desno){
    propagate(node, l, r);
    if(desno < l || levo > r)return {0, 0};
    if(l >= levo && r <= desno){
        return {seg[node].lg, seg[node].pref};
    }
    int mid = (l + r) / 2;
    pdl levi = query(node * 2, l, mid, levo, desno);
    pdl desni = query(node * 2 + 1, mid + 1, r, levo, desno);
    return max(levi, desni);
}




int init(int N, int X[], int Y[]) {
	n = N;
    y[0] = 1;
    for(int i=1; i<=n; i++){
        x[i] = X[i - 1];
        y[i] = Y[i - 1];
        lgx[i] = log10(1.0 * x[i]);
        lgy[i] = log10(1.0 * y[i]);
    }
    ll p = 1;
    for(int i=1; i<=n; i++){
        niz[i] = niz[i - 1] - lgy[i - 1] + lgx[i] + lgy[i];
        p = mul(p, x[i]);
        pro[i] = mul(p, y[i]);
    }
    seginit(1,1,n);
    return query(1,1,n,1,n).yy;
}

int updateX(int pos, int val){
    pos++;
    update(1,1,n,pos,n,log10(1.0 * val) - lgx[pos], mul(val, inverz(x[pos])));
    lgx[pos] = log10(val);
    x[pos] = val;
	return query(1,1,n,1,n).yy;
}

int updateY(int pos, int val) {
    pos++;
    update(1,1,n,pos,pos,log10(1.0 * val) - lgy[pos], mul(val, inverz(y[pos])));
    lgy[pos] = log10(val);
    y[pos] = val;
	return query(1,1,n,1,n).yy;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:110:33: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
         lgx[i] = log10(1.0 * x[i]);
                              ~~~^
horses.cpp:111:33: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
         lgy[i] = log10(1.0 * y[i]);
                              ~~~^
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
 #define yy second
            ^
horses.cpp:120:29: note: in expansion of macro 'yy'
     return query(1,1,n,1,n).yy;
                             ^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
 #define yy second
            ^
horses.cpp:128:26: note: in expansion of macro 'yy'
  return query(1,1,n,1,n).yy;
                          ^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
 #define yy second
            ^
horses.cpp:136:26: note: in expansion of macro 'yy'
  return query(1,1,n,1,n).yy;
                          ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 0 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 420 KB Output is correct
4 Correct 0 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 7 ms 404 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 508 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 4 ms 632 KB Output is correct
27 Correct 4 ms 632 KB Output is correct
28 Correct 4 ms 708 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 313 ms 106204 KB Output is correct
2 Correct 522 ms 106228 KB Output is correct
3 Correct 469 ms 106120 KB Output is correct
4 Correct 498 ms 106244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 9 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 6 ms 248 KB Output is correct
16 Correct 2 ms 296 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 508 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 174 ms 105208 KB Output is correct
34 Correct 174 ms 105208 KB Output is correct
35 Correct 187 ms 105276 KB Output is correct
36 Correct 189 ms 105308 KB Output is correct
37 Correct 148 ms 105208 KB Output is correct
38 Correct 153 ms 105208 KB Output is correct
39 Correct 132 ms 105208 KB Output is correct
40 Correct 163 ms 105336 KB Output is correct
41 Correct 132 ms 105308 KB Output is correct
42 Correct 135 ms 105264 KB Output is correct
43 Correct 142 ms 105084 KB Output is correct
44 Correct 142 ms 105248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 4 ms 632 KB Output is correct
27 Correct 4 ms 632 KB Output is correct
28 Correct 4 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 620 KB Output is correct
33 Correct 313 ms 106304 KB Output is correct
34 Correct 519 ms 106176 KB Output is correct
35 Correct 466 ms 106096 KB Output is correct
36 Correct 490 ms 106232 KB Output is correct
37 Correct 176 ms 105312 KB Output is correct
38 Correct 177 ms 105284 KB Output is correct
39 Correct 185 ms 105228 KB Output is correct
40 Correct 188 ms 105188 KB Output is correct
41 Correct 148 ms 105240 KB Output is correct
42 Correct 159 ms 105208 KB Output is correct
43 Correct 132 ms 105208 KB Output is correct
44 Correct 165 ms 105312 KB Output is correct
45 Correct 134 ms 105208 KB Output is correct
46 Correct 134 ms 105340 KB Output is correct
47 Correct 143 ms 105172 KB Output is correct
48 Correct 143 ms 105152 KB Output is correct
49 Correct 490 ms 111216 KB Output is correct
50 Correct 503 ms 111264 KB Output is correct
51 Correct 367 ms 118032 KB Output is correct
52 Correct 377 ms 117540 KB Output is correct
53 Correct 463 ms 109500 KB Output is correct
54 Correct 358 ms 110072 KB Output is correct
55 Correct 299 ms 108280 KB Output is correct
56 Correct 362 ms 113100 KB Output is correct
57 Correct 311 ms 108976 KB Output is correct
58 Correct 324 ms 109484 KB Output is correct
59 Correct 144 ms 111580 KB Output is correct