답안 #954503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954503 2024-03-28T05:11:49 Z irmuun 말 (IOI15_horses) C++17
0 / 100
382 ms 31876 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>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);
        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 true;
    }
    return (1ll*y[i]*more>1ll*y[j]);
}

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 0;
        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(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 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);
    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:67:76: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   67 |         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:79:51: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   79 |         Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 382 ms 31876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -