답안 #954566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954566 2024-03-28T07:11:10 Z irmuun 말 (IOI15_horses) C++17
100 / 100
510 ms 45324 KB
#include<bits/stdc++.h>
#include "horses.h"

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

const int maxn=5e5+5,inf=1e9;
const ll mod=1e9+7;

int n;
int x[maxn],y[maxn];

struct segtreeX{
    vector<int>d,Xmul;
    void init(){
        d.resize(4*n);
        Xmul.resize(4*n);
        build(1,0,n-1);
    }
    void build(int node,int l,int r){
        if(l==r){
            d[node]=x[l];
            Xmul[node]=x[l];
            return;
        }
        int mid=(l+r)/2;
        build(node*2,l,mid);
        build(node*2+1,mid+1,r);
        if(d[node*2]==inf+1||d[node*2+1]==inf+1){
            d[node]=inf+1;
        }
        else if(1ll*d[node*2]*d[node*2+1]>(ll)inf){
            d[node]=inf+1;
        }
        else{
            d[node]=d[node*2]*d[node*2+1];
        }
        Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
    }
    int query(int node,int l,int r,int L,int R){
        if(R<L||R<l||r<L) return -1;
        if(L<=l&&r<=R){
            return d[node];
        }
        int mid=(l+r)/2;
        int val1=query(node*2,l,mid,L,R),val2=query(node*2+1,mid+1,r,L,R);
        if(val1==-1) return val2;
        if(val2==-1) return val1;
        if(val1>inf||val2>inf){
            return inf+1;
        }
        else if(1ll*val1*val2>(ll)inf){
            return inf+1;
        }
        return val1*val2;
    }
    int product(int node,int l,int r,int L,int R){
        if(R<L||R<l||r<L) return 1;
        if(L<=l&&r<=R){
            return Xmul[node];
        }
        int mid=(l+r)/2;
        return (1ll*product(node*2,l,mid,L,R)*product(node*2+1,mid+1,r,L,R))%mod;
    }
    void update(int node,int l,int r,int pos,int val){
        if(r<pos||pos<l) return;
        if(l==r){
            d[node]=val;
            Xmul[node]=val;
            return;
        }
        int mid=(l+r)/2;
        update(node*2,l,mid,pos,val);
        update(node*2+1,mid+1,r,pos,val);
        if(d[node*2]==inf+1||d[node*2+1]==inf+1){
            d[node]=inf+1;
        }
        else if(1ll*d[node*2]*d[node*2+1]>(ll)inf){
            d[node]=inf+1;
        }
        else{
            d[node]=d[node*2]*d[node*2+1];
        }
        Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
    }
}sgx;

bool check(int i,int j){
    assert(i<j);
    int more=sgx.query(1,0,n-1,i+1,j);
    if(more==inf+1){
        return false;
    }
    return (1ll*y[i]>1ll*y[j]*more);
}

struct segtree{
    vector<int>d;
    void init(){
        d.resize(4*n);
        build(1,0,n-1);
    }
    void build(int node,int l,int r){
        if(l==r){
            d[node]=l;//index
            return;
        }
        int mid=(l+r)/2;
        build(node*2,l,mid);
        build(node*2+1,mid+1,r);
        int ind1=d[node*2],ind2=d[node*2+1];
        if(check(ind1,ind2)){
            d[node]=ind1;
        }
        else{
            d[node]=ind2;
        }
    }
    int query(int node,int l,int r,int L,int R){
        if(R<L||R<l||r<L) return -1;
        if(L<=l&&r<=R){
            return d[node];
        }
        int mid=(l+r)/2;
        int val1=query(node*2,l,mid,L,R),val2=query(node*2+1,mid+1,r,L,R);
        if(val1==-1) return val2;
        if(val2==-1) return val1;
        if(check(val1,val2)){
            return val1;
        }
        return val2;
    }
    void update(int node,int l,int r,int pos){
        if(r<pos||pos<l) return;
        if(l==r){
            d[node]=l;
            return;
        }
        int mid=(l+r)/2;
        update(node*2,l,mid,pos);
        update(node*2+1,mid+1,r,pos);
        int ind1=d[node*2],ind2=d[node*2+1];
        if(check(ind1,ind2)){
            d[node]=ind1;
        }
        else{
            d[node]=ind2;
        }
    }
}sg;

int solve(){
    int ind=sg.query(1,0,n-1,0,n-1);
    return 1ll*sgx.product(1,0,n-1,0,ind)*y[ind]%mod;
}

int init(int N,int X[],int Y[]){
    n=N;
    for(int i=0;i<n;i++){
        x[i]=X[i];
        y[i]=Y[i];
    }
    sgx.init();
    sg.init();
    return solve();
}

int updateX(int pos,int val){
    sgx.update(1,0,n-1,pos,val);
    sg.update(1,0,n-1,pos);
    return solve();
}

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

Compilation message

horses.cpp: In member function 'void segtreeX::build(int, int, int)':
horses.cpp:44:51: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   44 |         Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In member function 'int segtreeX::product(int, int, int, int, int)':
horses.cpp:69:77: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   69 |         return (1ll*product(node*2,l,mid,L,R)*product(node*2+1,mid+1,r,L,R))%mod;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In member function 'void segtreeX::update(int, int, int, int, int)':
horses.cpp:90:51: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   90 |         Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int solve()':
horses.cpp:160:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  160 |     return 1ll*sgx.product(1,0,n-1,0,ind)*y[ind]%mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2496 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2504 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 2 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 36496 KB Output is correct
2 Correct 309 ms 44984 KB Output is correct
3 Correct 365 ms 36440 KB Output is correct
4 Correct 360 ms 40424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2460 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2408 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2584 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2460 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 134 ms 35736 KB Output is correct
34 Correct 132 ms 35664 KB Output is correct
35 Correct 128 ms 42732 KB Output is correct
36 Correct 115 ms 42640 KB Output is correct
37 Correct 102 ms 33884 KB Output is correct
38 Correct 103 ms 34640 KB Output is correct
39 Correct 87 ms 33616 KB Output is correct
40 Correct 99 ms 37528 KB Output is correct
41 Correct 91 ms 33876 KB Output is correct
42 Correct 88 ms 33872 KB Output is correct
43 Correct 92 ms 38056 KB Output is correct
44 Correct 89 ms 38048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2484 KB Output is correct
15 Correct 1 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2684 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2512 KB Output is correct
24 Correct 2 ms 2392 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 2 ms 2508 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 1 ms 2512 KB Output is correct
33 Correct 242 ms 36604 KB Output is correct
34 Correct 299 ms 45324 KB Output is correct
35 Correct 374 ms 36600 KB Output is correct
36 Correct 417 ms 40136 KB Output is correct
37 Correct 133 ms 35668 KB Output is correct
38 Correct 130 ms 35664 KB Output is correct
39 Correct 120 ms 42700 KB Output is correct
40 Correct 115 ms 42576 KB Output is correct
41 Correct 103 ms 33856 KB Output is correct
42 Correct 102 ms 34664 KB Output is correct
43 Correct 85 ms 33816 KB Output is correct
44 Correct 100 ms 37692 KB Output is correct
45 Correct 95 ms 34024 KB Output is correct
46 Correct 90 ms 33872 KB Output is correct
47 Correct 88 ms 37980 KB Output is correct
48 Correct 90 ms 37908 KB Output is correct
49 Correct 510 ms 37704 KB Output is correct
50 Correct 467 ms 37868 KB Output is correct
51 Correct 285 ms 44516 KB Output is correct
52 Correct 226 ms 44048 KB Output is correct
53 Correct 383 ms 35932 KB Output is correct
54 Correct 290 ms 36532 KB Output is correct
55 Correct 196 ms 34832 KB Output is correct
56 Correct 227 ms 39336 KB Output is correct
57 Correct 283 ms 35516 KB Output is correct
58 Correct 247 ms 35920 KB Output is correct
59 Correct 93 ms 38008 KB Output is correct