Submission #791180

# Submission time Handle Problem Language Result Execution time Memory
791180 2023-07-23T13:56:56 Z Khizri Horses (IOI15_horses) C++17
37 / 100
525 ms 52996 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();
	ll res=query2(1,1,n,1,n);
	if(st.size()){
        it=--st.end();
	}
	else{
        return res;
	}
	ll a=1;
	vector<int>vt;
	while(k--){
        int x=*it;
        a=1ll*a*idx[x];
        vt.pb(x);
        if(a>=1e9) break;
        it--;
	}
	unsigned ll ans=1;
	unsigned ll mx=1;
	reverse(all(vt));
	int q=-1;
	vt.pb(n+1);
	for(int i=0;i<vt.size()-1;i++){
        ans*=idx[vt[i]];
        int l=vt[i],r=vt[i+1]-1;
        unsigned ll k=ans*query2(1,1,n,l,n);
        if(k>mx){
            mx=k;
            q=i;
        }
	}
	if(q==-1) return res;
	int l=vt[q],r=vt[q+1]-1;
	res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
	return res;
}

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(32,(int)st.size());
	auto it=st.end();
	ll res=query2(1,1,n,1,n);
	if(st.size()){
        it=--st.end();
	}
	else{
        return res;
	}
	ll a=1;
	vector<int>vt;
	while(k--){
        int x=*it;
        a=1ll*a*idx[x];
        vt.pb(x);
        if(a>=1e9) break;
        it--;
	}
	unsigned ll ans=1;
	unsigned ll mx=1;
	reverse(all(vt));
	int q=-1;
	vt.pb(n+1);
	for(int i=0;i<vt.size()-1;i++){
        ans*=idx[vt[i]];
        int l=vt[i],r=vt[i+1]-1;
        unsigned ll k=ans*query2(1,1,n,l,n);
        if(k>mx){
            mx=k;
            q=i;
        }
	}
	if(q==-1) return res;
	int l=vt[q],r=vt[q+1]-1;
	res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
	return res;
}

int updateY(int pos, int val) {
	pos++;
	arr[pos]=val;
	update2(1,1,n,pos,val);
	int k=min(32,(int)st.size());
	auto it=st.end();
	ll res=query2(1,1,n,1,n);
	if(st.size()){
        it=--st.end();
	}
	else{
        return res;
	}
	ll a=1;
	vector<int>vt;
	while(k--){
        int x=*it;
        a=1ll*a*idx[x];
        vt.pb(x);
        if(a>=1e9) break;
        it--;
	}
	unsigned ll ans=1;
	unsigned ll mx=1;
	reverse(all(vt));
	int q=-1;
	vt.pb(n+1);
	for(int i=0;i<vt.size()-1;i++){
        ans*=idx[vt[i]];
        int l=vt[i],r=vt[i+1]-1;
        unsigned ll k=ans*query2(1,1,n,l,n);
        if(k>mx){
            mx=k;
            q=i;
        }
	}
	if(q==-1) return res;
	int l=vt[q],r=vt[q+1]-1;
	res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
	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:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |  ll res=query2(1,1,n,1,n);
      |                    ^
horses.cpp:86:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |  ll res=query2(1,1,n,1,n);
      |                        ^
horses.cpp:91:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   91 |         return res;
      |                ^~~
horses.cpp:99:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   99 |         if(a>=1e9) break;
      |            ^
horses.cpp:106:9: warning: conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} may change value [-Wconversion]
  106 |  vt.pb(n+1);
      |        ~^~
horses.cpp:107:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |  for(int i=0;i<vt.size()-1;i++){
      |              ~^~~~~~~~~~~~
horses.cpp:110:21: warning: declaration of 'k' shadows a previous local [-Wshadow]
  110 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                     ^
horses.cpp:84:6: note: shadowed declaration is here
   84 |  int k=min(32,(int)st.size());
      |      ^
horses.cpp:110:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  110 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                                      ^
horses.cpp:110:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  110 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                                          ^
horses.cpp:109:21: warning: unused variable 'r' [-Wunused-variable]
  109 |         int l=vt[i],r=vt[i+1]-1;
      |                     ^
horses.cpp:116:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  116 |  if(q==-1) return res;
      |                   ^~~
horses.cpp:118:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  118 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                     ^
horses.cpp:118:43: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  118 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                                           ^
horses.cpp:118:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  118 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                                               ^
horses.cpp:119:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  119 |  return res;
      |         ^~~
horses.cpp:117:14: warning: unused variable 'r' [-Wunused-variable]
  117 |  int l=vt[q],r=vt[q+1]-1;
      |              ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:131:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  131 |  update(1,1,n,pos,val);
      |             ^
horses.cpp:134:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  134 |  ll res=query2(1,1,n,1,n);
      |                    ^
horses.cpp:134:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  134 |  ll res=query2(1,1,n,1,n);
      |                        ^
horses.cpp:139:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  139 |         return res;
      |                ^~~
horses.cpp:147:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
  147 |         if(a>=1e9) break;
      |            ^
horses.cpp:154:9: warning: conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} may change value [-Wconversion]
  154 |  vt.pb(n+1);
      |        ~^~
horses.cpp:155:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  155 |  for(int i=0;i<vt.size()-1;i++){
      |              ~^~~~~~~~~~~~
horses.cpp:158:21: warning: declaration of 'k' shadows a previous local [-Wshadow]
  158 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                     ^
horses.cpp:132:6: note: shadowed declaration is here
  132 |  int k=min(32,(int)st.size());
      |      ^
horses.cpp:158:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  158 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                                      ^
horses.cpp:158:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  158 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                                          ^
horses.cpp:157:21: warning: unused variable 'r' [-Wunused-variable]
  157 |         int l=vt[i],r=vt[i+1]-1;
      |                     ^
horses.cpp:164:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  164 |  if(q==-1) return res;
      |                   ^~~
horses.cpp:166:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  166 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                     ^
horses.cpp:166:43: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  166 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                                           ^
horses.cpp:166:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  166 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                                               ^
horses.cpp:167:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  167 |  return res;
      |         ^~~
horses.cpp:165:14: warning: unused variable 'r' [-Wunused-variable]
  165 |  int l=vt[q],r=vt[q+1]-1;
      |              ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:173:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  173 |  update2(1,1,n,pos,val);
      |              ^
horses.cpp:176:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  176 |  ll res=query2(1,1,n,1,n);
      |                    ^
horses.cpp:176:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  176 |  ll res=query2(1,1,n,1,n);
      |                        ^
horses.cpp:181:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  181 |         return res;
      |                ^~~
horses.cpp:189:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
  189 |         if(a>=1e9) break;
      |            ^
horses.cpp:196:9: warning: conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} may change value [-Wconversion]
  196 |  vt.pb(n+1);
      |        ~^~
horses.cpp:197:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  197 |  for(int i=0;i<vt.size()-1;i++){
      |              ~^~~~~~~~~~~~
horses.cpp:200:21: warning: declaration of 'k' shadows a previous local [-Wshadow]
  200 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                     ^
horses.cpp:174:6: note: shadowed declaration is here
  174 |  int k=min(32,(int)st.size());
      |      ^
horses.cpp:200:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  200 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                                      ^
horses.cpp:200:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  200 |         unsigned ll k=ans*query2(1,1,n,l,n);
      |                                          ^
horses.cpp:199:21: warning: unused variable 'r' [-Wunused-variable]
  199 |         int l=vt[i],r=vt[i+1]-1;
      |                     ^
horses.cpp:206:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  206 |  if(q==-1) return res;
      |                   ^~~
horses.cpp:208:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  208 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                     ^
horses.cpp:208:43: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  208 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                                           ^
horses.cpp:208:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  208 |  res=(1ll*query(1,1,n,1,vt[q])*query2(1,1,n,l,n))%MOD;
      |                                               ^
horses.cpp:209:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  209 |  return res;
      |         ^~~
horses.cpp:207:14: warning: unused variable 'r' [-Wunused-variable]
  207 |  int l=vt[q],r=vt[q+1]-1;
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Incorrect 3 ms 340 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 525 ms 52996 KB Output is correct
2 Correct 282 ms 52836 KB Output is correct
3 Correct 294 ms 52868 KB Output is correct
4 Correct 362 ms 52844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 276 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Incorrect 2 ms 340 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Incorrect 2 ms 340 KB Output isn't correct
28 Halted 0 ms 0 KB -