Submission #838346

# Submission time Handle Problem Language Result Execution time Memory
838346 2023-08-26T16:44:10 Z AbdelmagedNour Horses (IOI15_horses) C++17
17 / 100
527 ms 52424 KB
#include <bits/stdc++.h>
using namespace std;
//#include "grader.cpp"
#include "horses.h"
typedef long long ll;
const ll mod=(1e9)+7,MAXN=500005;
ll add(ll a,ll b){
	a+=b;
    if(a>=mod)a-=mod;
    return a;
}
ll sub(ll a,ll b){
    a-=b;
    if(a<0)a+=mod;
    return a;
}
ll mul(ll a,ll b){
	return(a*1LL*b)%mod;
}
ll power(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1)res=mul(res,x);
        x=mul(x,x);
        n>>=1;
    }
    return res;
}
ll inv(ll a){
	return power(a,mod-2);
}
ll divide(ll a,ll b){
	return mul(a,inv(b));
}
ll x[MAXN],y[MAXN],n;
set<ll>not_one;
ll bit[MAXN],tree[1<<21];
void upd(ll i,ll val){
    for(;i<=n;i+=(i&(-i)))bit[i]=mul(bit[i],val);
}
ll qry(ll i){
	ll res=1;
    for(;i>=1;i-=(i&(-i)))res=mul(res,bit[i]);
	return res;
}
void update(ll l,ll r,ll p,ll idx,ll val){
    if(l==r){
        tree[p]=val;
        return;
    }
    ll md=(l+r)>>1;
    if(md>=idx)update(l,md,p*2+1,idx,val);
    else update(md+1,r,p*2+2,idx,val);
    tree[p]=max(tree[p*2+1],tree[p*2+2]);
}
ll query(ll l,ll r,ll p,ll l_q,ll r_q){
    if(l>r_q||r<l_q)return 1;
    if(l>=l_q&&r<=r_q)return tree[p];
    ll md=(l+r)>>1;
    return max(query(l,md,p*2+1,l_q,r_q),query(md+1,r,p*2+2,l_q,r_q));
}
ll solve(){
	long long cur_factor=1,all_factor=1;
	ll last=n+1;
	long long ans=0,best=0;
	for(auto it=not_one.rbegin();it!=not_one.rend();it++){
		ll cur_pos=*it;
	    ll cur_y=query(1,n,0,cur_pos,last-1);
		if(cur_y>best*cur_factor) {
			best=cur_y;
			ans=mul(qry(cur_pos),cur_y);
			cur_factor=1;
		}
		cur_factor*=x[cur_pos];
		all_factor*=x[cur_pos];
		if(all_factor>mod-7)break;
		last=cur_pos;
	}
	return ans%mod;
}
int init(int N, int X[], int Y[]) {
	n=N;
	x[0]=y[0]=1;
	for(ll i=1;i<=n;i++)x[i]=X[i-1],y[i]=Y[i-1];
	for(ll i=0;i<=n;i++)bit[i]=1;
	for(ll i=1;i<=n;i++){
		upd(i,x[i]);
		update(1,n,0,i,y[i]);
	}
	for(ll i=1;i<=n;i++){
		if(x[i]>1)not_one.insert(i);
	}
	not_one.insert(1);
	return solve();
}
int updateX(int pos,int val){	
    pos++;
    upd(pos,divide(val,x[pos]));
	if(x[pos]>1&&pos>1)not_one.erase(pos);
    if(val>1)not_one.insert(pos);
    not_one.insert(1);
    x[pos]=val;
    return solve();
}
int updateY(int pos,int val){
    pos++;
    y[pos]=val;
    update(1,n,1,pos,val);
	return solve();
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:94:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   94 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:103:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  103 |     return solve();
      |            ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:109:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  109 |  return solve();
      |         ~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 316 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 340 KB Output is correct
14 Correct 1 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 0 ms 312 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 527 ms 52424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 0 ms 320 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 1 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 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
13 Correct 0 ms 312 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 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 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -