Submission #954555

#TimeUsernameProblemLanguageResultExecution timeMemory
954555irmuunHorses (IOI15_horses)C++17
17 / 100
242 ms45224 KiB
#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); return solve(); } int updateY(int pos,int val){ y[pos]=val; sg.update(1,0,n-1,pos); return solve(); }

Compilation message (stderr)

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;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
#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...