Submission #408755

#TimeUsernameProblemLanguageResultExecution timeMemory
408755MDarioHorses (IOI15_horses)C++11
100 / 100
182 ms46300 KiB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
const ll mod=1e9+7;
ll a[500001], b[500001];
pair<pair<ll, ll>, pair<ll, ll>> st[2000001];
void f(ll xf){
    if(st[xf*2+1].S.F==1){
        st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {1, st[xf*2+1].S.S}};
    }
    else{
        if(st[xf*2].F.S<st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S){
            st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {(st[xf*2].S.F||(st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S*st[xf*2].F.F)>=1e9), st[xf*2+1].S.S}};
        }
        else{
            st[xf]=st[xf*2];
            st[xf].S.S*=st[xf*2+1].S.S*st[xf*2+1].F.F;
        }
    }
    return ;
}
void build(ll xf, ll lf, ll rf){
    if(lf==rf){
        st[xf]={{a[lf], b[lf]}, {(a[lf]*b[lf]>=1e9), 1}};
        return;
    }
    build(xf*2, lf, (lf+rf)/2);
    build(xf*2+1, (lf+rf)/2+1, rf);
    f(xf);
    return ;
}
ll n;
void update(ll xf, ll lf, ll rf, ll of){
    if(rf<of||lf>of)return;
    if(lf==rf){
        st[xf]={{a[lf], b[lf]}, {(a[lf]*b[lf]>=1e9), 1}};
        return;
    }
    update(xf*2, lf, (lf+rf)/2, of);
    update(xf*2+1, (lf+rf)/2+1, rf, of);
    f(xf);
    return ;
}
int init(int N, int X[], int Y[]) {
    n=N;
    for(int i=0; i<N; i++){
        a[i+1]=X[i];
        b[i+1]=Y[i];
    }
    build(1, 1, N);
	return (st[1].F.F*st[1].F.S)%mod;
}

int updateX(int pos, int val) {
    a[pos+1]=val;
    update(1, 1, n, pos+1);
	return (st[1].F.F*st[1].F.S)%mod;
}

int updateY(int pos, int val) {
    b[pos+1]=val;
    update(1, 1, n, pos+1);
	return (st[1].F.F*st[1].F.S)%mod;
}

Compilation message (stderr)

horses.cpp: In function 'void f(ll)':
horses.cpp:16:154: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   16 |             st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {(st[xf*2].S.F||(st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S*st[xf*2].F.F)>=1e9), st[xf*2+1].S.S}};
      |                                                                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
horses.cpp: In function 'void build(ll, ll, ll)':
horses.cpp:27:40: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   27 |         st[xf]={{a[lf], b[lf]}, {(a[lf]*b[lf]>=1e9), 1}};
      |                                   ~~~~~^~~~~~
horses.cpp: In function 'void update(ll, ll, ll, ll)':
horses.cpp:39:40: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   39 |         st[xf]={{a[lf], b[lf]}, {(a[lf]*b[lf]>=1e9), 1}};
      |                                   ~~~~~^~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:54:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   54 |  return (st[1].F.F*st[1].F.S)%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:60:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   60 |  return (st[1].F.F*st[1].F.S)%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:66:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   66 |  return (st[1].F.F*st[1].F.S)%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
#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...