Submission #790961

# Submission time Handle Problem Language Result Execution time Memory
790961 2023-07-23T10:02:51 Z Khizri Horses (IOI15_horses) C++17
Compilation error
0 ms 0 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=5e5+5;
ll n,idx[mxn],arr[mxn],tree2[mxn*4];
ll tree[4*mxn];
set<int>st;
void build(int node,int l,int r){
    if(l==r){
        tree[node]=idx[l];
        return;
    }
    int m=(l+r)/2;
    build(2*node,l,m);
    build(2*node+1,m+1,r);
    tree[node]=(tree[2*node]*tree[2*node+1])%MOD;
}
void build2(int node,int l,int r){
    if(l==r){
        tree2[node]=arr[l];
        return;
    }
    int m=(l+r)/2;
    build2(2*node,l,m);
    build2(2*node+1,m+1,r);
    tree2[node]=max(tree2[2*node],tree2[2*node+1]);
}
void update(int node,int l,int r,int pos,int val){
    if(l>pos||r<pos) return;
    if(l==r){
        tree[node]=val;
        return;
    }
    int m=(l+r)/2;
    update(2*node,l,m,pos,val);
    update(2*node+1,m+1,r,pos,val);
    tree[node]=(tree[2*node]*tree[2*node+1])%MOD;
}
void update2(int node,int l,int r,int pos,int val){
    if(l>pos||r<pos) return;
    if(l==r){
        tree2[node]=val;
        return;
    }
    int m=(l+r)/2;
    update2(2*node,l,m,pos,val);
    update2(2*node+1,m+1,r,pos,val);
    tree2[node]=max(tree2[2*node],tree2[2*node+1]);
}
ll query(int node,int l,int r,int ql,int qr){
    if(l>qr||r<ql) return 1;
    if(ql<=l&&r<=qr) return tree[node];
    int m=(l+r)/2;
    return (query(2*node,l,m,ql,qr)*query(2*node+1,m+1,r,ql,qr))%MOD;
}
int query2(int node,int l,int r,int ql,int qr){
    if(l>qr||r<ql) return 0;
    if(ql<=l&&r<=qr) return tree2[node];
    int m=(l+r)/2;
    return max(query2(2*node,l,m,ql,qr),query2(2*node+1,m+1,r,ql,qr));
}
int init(int N, int X[], int Y[]) {
	n=N;
	for(int i=0;i<n;i++){
        arr[i+1]=Y[i];
        idx[i+1]=X[i];
        if(idx[i+1]>1){
            st.insert(i+1);
        }
	}
	build(1,1,n);
	build2(1,1,n);
	int k=min(32,(int)st.size());
	auto it=--st.end();
	int res=query2(1,1,n,1,n);
	while(k--){
        int x=*it;
        ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n));
        res=max(res,ans);
        it--;
	}
	return res%MOD;
}

int updateX(int pos, int val) {
	pos++;
	if(idx[pos]>1){
        st.erase(pos);
	}
	idx[pos]=val;
	if(idx[pos]>1){
        st.insert(pos);
	}
	update(1,1,n,pos,val);
	int k=min(33,(int)st.size());
	auto it=--st.end();
	int res=query2(1,1,n,1,n);
	while(k--){
        int x=*it;
        ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD;
        res=max(res,(int)ans);
        it--;
	}
	return res;
}

int updateY(int pos, int val) {
	pos++;
	arr[pos]=val;
	update2(1,1,n,pos,val);
	int k=min(33,(int)st.size());
	auto it=--st.end();
	int res=query2(1,1,n,1,n);
	while(k--){
        int x=*it;
        ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD;
        res=max(res,(int)ans);
        it--;
	}
	return res;
}

Compilation message

horses.cpp: In function 'int query2(int, int, int, int, int)':
horses.cpp:69:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   69 |     if(ql<=l&&r<=qr) return tree2[node];
      |                             ~~~~~~~~~~^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:82:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   82 |  build(1,1,n);
      |            ^
horses.cpp:83:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   83 |  build2(1,1,n);
      |             ^
horses.cpp:86:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |  int res=query2(1,1,n,1,n);
      |                     ^
horses.cpp:86:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |  int res=query2(1,1,n,1,n);
      |                         ^
horses.cpp:89:27: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   89 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n));
      |                           ^
horses.cpp:89:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   89 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n));
      |                                             ^
horses.cpp:89:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   89 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n));
      |                                                 ^
horses.cpp:90:24: error: no matching function for call to 'max(int&, long long int&)'
   90 |         res=max(res,ans);
      |                        ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from horses.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
horses.cpp:90:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   90 |         res=max(res,ans);
      |                        ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from horses.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
horses.cpp:90:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   90 |         res=max(res,ans);
      |                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from horses.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
horses.cpp:90:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   90 |         res=max(res,ans);
      |                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from horses.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
horses.cpp:90:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   90 |         res=max(res,ans);
      |                        ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:105:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  105 |  update(1,1,n,pos,val);
      |             ^
horses.cpp:108:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  108 |  int res=query2(1,1,n,1,n);
      |                     ^
horses.cpp:108:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  108 |  int res=query2(1,1,n,1,n);
      |                         ^
horses.cpp:111:27: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  111 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD;
      |                           ^
horses.cpp:111:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  111 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD;
      |                                             ^
horses.cpp:111:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  111 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD;
      |                                                 ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:121:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  121 |  update2(1,1,n,pos,val);
      |              ^
horses.cpp:124:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  124 |  int res=query2(1,1,n,1,n);
      |                     ^
horses.cpp:124:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  124 |  int res=query2(1,1,n,1,n);
      |                         ^
horses.cpp:127:27: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  127 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD;
      |                           ^
horses.cpp:127:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  127 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD;
      |                                             ^
horses.cpp:127:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  127 |         ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD;
      |                                                 ^