제출 #522832

#제출 시각아이디문제언어결과실행 시간메모리
522832Deepesson말 (IOI15_horses)C++17
17 / 100
13 ms8396 KiB
#include <bits/stdc++.h>
#include "horses.h"
#define MAX 105000
typedef long long ll;
typedef std::pair<ll,bool> plb;

long long MOD = 1e9+7;
plb mul(plb a,plb b){
    plb c;
    c.first=a.first*b.first;
    c.second=std::max(a.second,b.second);
    if(c.first>=MOD){
        c.second=true;
        c.first%=MOD;
    }
    return c;
}
typedef std::pair<plb,ll> ppi;
ll n;
ppi mul(ppi a,ppi b){
    plb c=mul(a.first,b.first);
    ppi d;
    d.first=c;
    d.second=a.second;
    return d;
}
ppi tab[MAX*4];

void update(int t,int j,int la=0,int ra=n-1,int pos=1){
    int m = (la+ra)/2;
    if(ra<t||la>t)return;
    if(la==ra){
        tab[pos].second=t;
        tab[pos].first.first=j;
        tab[pos].first.second=false;
        return;
    }
    update(t,j,la,m,pos*2);
    update(t,j,m+1,ra,(pos*2)+1);
    tab[pos]=mul(tab[pos*2],tab[(pos*2)+1]);
}
ppi omega;
ppi nrmquery(int l,int r,int la=0,int ra=n-1,int pos=1){
    if(l>ra||r<la)return omega;
    if(l<=la&&r>=ra){
        return tab[pos];
    }
    int m = (la+ra)/2;
    return mul(nrmquery(l,r,la,m,pos*2),nrmquery(l,r,m+1,ra,(pos*2)+1));
}

int query(void){
    int l=0,r=n-1;
    while(l<r){
        int m = (l+r)/2;
        if(nrmquery(m,n-1).first.second){
            l=m+1;
        }else r=m;
    }
    return l;
}

typedef std::array<std::array<long long,2>,2> matriz;
matriz mul(matriz a,matriz b){
    matriz c={};
    for(int i=0;i!=2;++i){
        for(int j=0;j!=2;++j){
            for(int k=0;k!=2;++k){
                ///Nunca vai ter q usar o MOD, estou fazendo malandragem para isso
                c[i][j]=std::max(c[i][j],(a[i][k]*b[k][j]));
            }
        }
    }
    return c;
}
matriz mattab[MAX*4];
matriz neutro;
void matupdate(int t,matriz k,int la=0,int ra=n-1,int pos=1){
    if(ra<t||la>t)return;
    if(la==ra){
        mattab[pos]=k;
        return;
    }
    int m = (la+ra)/2;
    matupdate(t,k,la,m,pos*2);
    matupdate(t,k,m+1,ra,(pos*2)+1);
    mattab[pos]=mul(mattab[pos*2],mattab[(pos*2)+1]);
}
matriz matquery(int l,int r,int la=0,int ra=n-1,int pos=1){
    if(l>ra||r<la)return neutro;
    if(l<=la&&r>=ra){
        return mattab[pos];
    }
    int m = (la+ra)/2;
    return mul(matquery(l,r,la,m,pos*2),matquery(l,r,m+1,ra,(pos*2)+1));
}
matriz gerarmat(int X,int Y){
    matriz a={},b={};
    a[0][0]=X;
    a[1][1]=1;
    b[0][0]=1;
    b[1][1]=1;
    b[0][1]=Y;
    return mul(a,b);
}
ll x[MAX],y[MAX];
int get(void){
    int l = query();
    long long base=1;
    if(l){
        auto u = nrmquery(0,l-1);
        base=u.first.first;
    }
  //  std::cout<<base<<" "<<l<<"\n";
    matriz a={};
    a[0][0]=base;
    matriz b = matquery(l,n-1);
   // std::cout<<b[0][1]<<"\n";
    if(l){
        matriz g={};g[0][0]=1;
        matriz k=mul(g,b);
        long long rate = std::max(k[0][1],y[l-1]);
        return (rate*base)%MOD;
    }
    a=mul(a,b);
    return a[0][1]%MOD;
}
int init(int N, int X[], int Y[]) {
    omega.first.first=1;
    neutro[0][0]=neutro[1][1]=1;
    n=N;
    for(int i=0;i!=N;++i){
        update(i,X[i]);
    }
    for(int i=0;i!=N;++i){
        x[i]=X[i],y[i]=Y[i];
        matupdate(i,gerarmat(X[i],Y[i]));
    }
	return get();
}

int updateX(int pos, int val) {
    x[pos]=val;
    update(pos,val);
    matupdate(pos,gerarmat(x[pos],y[pos]));
	return get();
}

int updateY(int pos, int val) {
    y[pos]=val;
    matupdate(pos,gerarmat(x[pos],y[pos]));
	return get();
}

컴파일 시 표준 에러 (stderr) 메시지

horses.cpp:29:42: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   29 | void update(int t,int j,int la=0,int ra=n-1,int pos=1){
      |                                         ~^~
horses.cpp:43:43: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   43 | ppi nrmquery(int l,int r,int la=0,int ra=n-1,int pos=1){
      |                                          ~^~
horses.cpp: In function 'int query()':
horses.cpp:53:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   53 |     int l=0,r=n-1;
      |               ~^~
horses.cpp:56:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   56 |         if(nrmquery(m,n-1).first.second){
      |                       ~^~
horses.cpp:56:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   56 |         if(nrmquery(m,n-1).first.second){
      |                          ^
horses.cpp: At global scope:
horses.cpp:78:48: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   78 | void matupdate(int t,matriz k,int la=0,int ra=n-1,int pos=1){
      |                                               ~^~
horses.cpp:89:46: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   89 | matriz matquery(int l,int r,int la=0,int ra=n-1,int pos=1){
      |                                             ~^~
horses.cpp: In function 'int get()':
horses.cpp:111:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  111 |         auto u = nrmquery(0,l-1);
      |                                ^
horses.cpp:117:28: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  117 |     matriz b = matquery(l,n-1);
      |                           ~^~
horses.cpp:117:30: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  117 |     matriz b = matquery(l,n-1);
      |                              ^
horses.cpp:123:27: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  123 |         return (rate*base)%MOD;
      |                ~~~~~~~~~~~^~~~
horses.cpp:126:19: warning: conversion from 'std::array<long long int, 2>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  126 |     return a[0][1]%MOD;
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:133:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  133 |         update(i,X[i]);
      |                      ^
horses.cpp:137:40: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  137 |         matupdate(i,gerarmat(X[i],Y[i]));
      |                                        ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:144:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  144 |     update(pos,val);
      |                   ^
horses.cpp:145:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  145 |     matupdate(pos,gerarmat(x[pos],y[pos]));
      |                            ~~~~~^
horses.cpp:145:40: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  145 |     matupdate(pos,gerarmat(x[pos],y[pos]));
      |                                   ~~~~~^
horses.cpp:145:42: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  145 |     matupdate(pos,gerarmat(x[pos],y[pos]));
      |                                          ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:151:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  151 |     matupdate(pos,gerarmat(x[pos],y[pos]));
      |                            ~~~~~^
horses.cpp:151:40: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  151 |     matupdate(pos,gerarmat(x[pos],y[pos]));
      |                                   ~~~~~^
horses.cpp:151:42: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  151 |     matupdate(pos,gerarmat(x[pos],y[pos]));
      |                                          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...