답안 #206985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
206985 2020-03-06T03:09:16 Z oscarsierra12 말 (IOI15_horses) C++14
100 / 100
1267 ms 53240 KB
#include "horses.h"
#include <bits/stdc++.h>

#define ff       first
#define ss       second
#define pb       push_back

using namespace std ;

typedef long long     ll ;
typedef pair<ll, int> pli ;
typedef pair<pli, pli> iii ;

const int N = 1e7 ;
const int o = 5e5+2 ;
const int mod = 1e9+7 ;

int lft[N], rg[N];
ll mx[N], mult[N] ;
int supMod[N] ;
int mnPos[N] ;
int cntNode = 0 ;
int arx[o], ary[o] ;
int n ;

void build ( int nod, int l, int r ) {
    int mid = (l+r)/2 ;
    if ( l == r ) {
        mx [nod] = ary[l] ;
        mult [nod] = arx[l] ;
        if ( arx[l] == 1 ) mnPos[nod] = n ;
        else mnPos[nod] = l ;
        supMod[nod] = 0 ;
        return ;
    }
    build ( lft[nod] = ++cntNode , l, mid ) ;
    build ( rg[nod] = ++cntNode , mid+1, r ) ;
    mx[nod] = max ( mx[lft[nod]], mx[rg[nod]] ) ;
    mnPos[nod] = min ( mnPos[lft[nod]], mnPos[rg[nod]] ) ;
    mult[nod] = mult[lft[nod]] * mult[rg[nod]] ;
    if ( mult[nod] > mod ) supMod[nod] = 1 ;
    else supMod[nod] = (supMod[lft[nod]] || supMod[rg[nod]]) ;
    mult[nod] %= mod ;
}

void update ( int nod, int l, int r, int a, int x, int y ) {
    int mid = (l+r)/2 ;
    if ( l == a && r == a ) {
        mx[nod] = y ;
        mult[nod] = x ;
        if ( x == 1 ) mnPos[nod] = n ;
        else mnPos[nod] = l ;
        supMod[nod] = 0 ;
        return ;
    }
    if ( a <= mid ) update ( lft[nod], l, mid, a, x, y ) ;
    else update ( rg[nod], mid+1, r, a, x, y ) ;
    mx[nod] = max ( mx[lft[nod]], mx[rg[nod]] ) ;
    mult[nod] = mult[lft[nod]] * mult[rg[nod]] ;
    mnPos[nod] = min ( mnPos[lft[nod]], mnPos[rg[nod]] ) ;
    if ( mult[nod] > mod ) supMod[nod] = 1 ;
    else supMod[nod] = (supMod[lft[nod]] || supMod[rg[nod]]) ;
    mult[nod] %= mod ;
}

iii query ( int nod, int l, int r, int a, int b ) {
    int mid = (l+r)/2 ;
    if ( a > b ) return {{1, n},{1,1}};
    if ( l == a && r == b ) return {{mx[nod],mnPos[nod]}, {mult[nod], supMod[nod]}} ;
    if ( b <= mid ) return query ( lft[nod], l, mid, a, b ) ;
    if ( a > mid ) return query ( rg[nod], mid+1, r, a, b ) ;
    iii L = query ( lft[nod], l, mid, a, mid ) ;
    iii R = query ( rg[nod], mid+1, r, mid+1, b ) ;
    return {{max (L.ff.ff, R.ff.ff),min(L.ff.ss, R.ff.ss)}, {1ll*(L.ss.ff * R.ss.ff)%mod, (L.ss.ff * R.ss.ff > mod || L.ss.ss || R.ss.ss )}};
}

int solve () {
    int l = 0, r = n-1 ;
    while ( l < r ) {
        int mid = (l+r)>>1 ;
        if ( query(0,0,n-1,mid,n-1).ss.ss ) l = mid+1 ;
        else r = mid ;
    }
    ll ans = query(0,0,n-1,0,l-1).ss.ff ;
    ll psb = (l?ary[l-1]:0) ;
    ll best = 0, cur = 1 ;
    int bg = l ;
    while ( bg < n ) {
        l = query (0,0,n-1, bg+1, n-1).ff.ss ;
        best = max ( best, cur * query(0,0,n-1,bg,l-1).ff.ff * arx[bg] ) ;
        cur *= arx[bg] ;
        bg = l ;
    }
    if ( psb > best ) return (ans*psb)%mod ;
    best %= mod ;
    return (ans*best)%mod ;
}

int init(int Ne, int X[], int Y[]) {
    for ( int i = 0 ; i < Ne; ++i )
        arx[i] = X[i], ary[i] = Y[i] ;
    n = Ne ;
    build ( 0,0,n-1 ) ;
    return solve();
}

int updateX(int pos, int val) {
    update ( 0,0,n-1,pos,val,ary[pos]) ;
    arx[pos] = val ;
	return solve();
}

int updateY(int pos, int val) {
    update ( 0,0,n-1,pos,arx[pos],val) ;
    ary[pos] = val ;
	return solve();
}

Compilation message

horses.cpp: In function 'int solve()':
horses.cpp:94:39: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
     if ( psb > best ) return (ans*psb)%mod ;
                              ~~~~~~~~~^~~~
horses.cpp:96:22: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
     return (ans*best)%mod ;
            ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 380 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 13 ms 376 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 380 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 10 ms 504 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 8 ms 504 KB Output is correct
32 Correct 12 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 733 ms 40724 KB Output is correct
2 Correct 459 ms 40824 KB Output is correct
3 Correct 457 ms 41004 KB Output is correct
4 Correct 508 ms 40952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 11 ms 504 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 7 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 8 ms 504 KB Output is correct
32 Correct 9 ms 504 KB Output is correct
33 Correct 98 ms 40056 KB Output is correct
34 Correct 88 ms 40056 KB Output is correct
35 Correct 110 ms 39800 KB Output is correct
36 Correct 99 ms 39800 KB Output is correct
37 Correct 199 ms 40440 KB Output is correct
38 Correct 84 ms 40056 KB Output is correct
39 Correct 88 ms 40056 KB Output is correct
40 Correct 91 ms 39928 KB Output is correct
41 Correct 113 ms 40056 KB Output is correct
42 Correct 127 ms 40056 KB Output is correct
43 Correct 64 ms 39800 KB Output is correct
44 Correct 61 ms 39800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 372 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 400 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 9 ms 504 KB Output is correct
28 Correct 7 ms 504 KB Output is correct
29 Correct 7 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 8 ms 504 KB Output is correct
32 Correct 9 ms 504 KB Output is correct
33 Correct 716 ms 41208 KB Output is correct
34 Correct 479 ms 53240 KB Output is correct
35 Correct 478 ms 44444 KB Output is correct
36 Correct 515 ms 48120 KB Output is correct
37 Correct 100 ms 43512 KB Output is correct
38 Correct 93 ms 43512 KB Output is correct
39 Correct 120 ms 50680 KB Output is correct
40 Correct 111 ms 50424 KB Output is correct
41 Correct 197 ms 41720 KB Output is correct
42 Correct 83 ms 42616 KB Output is correct
43 Correct 86 ms 41592 KB Output is correct
44 Correct 94 ms 45688 KB Output is correct
45 Correct 123 ms 41752 KB Output is correct
46 Correct 124 ms 41720 KB Output is correct
47 Correct 66 ms 45944 KB Output is correct
48 Correct 66 ms 45948 KB Output is correct
49 Correct 506 ms 45560 KB Output is correct
50 Correct 436 ms 45560 KB Output is correct
51 Correct 402 ms 52508 KB Output is correct
52 Correct 315 ms 52088 KB Output is correct
53 Correct 1267 ms 44024 KB Output is correct
54 Correct 435 ms 44636 KB Output is correct
55 Correct 545 ms 42744 KB Output is correct
56 Correct 347 ms 47352 KB Output is correct
57 Correct 718 ms 43384 KB Output is correct
58 Correct 915 ms 43768 KB Output is correct
59 Correct 62 ms 45944 KB Output is correct