Submission #796400

# Submission time Handle Problem Language Result Execution time Memory
796400 2023-07-28T11:11:35 Z Rafi22 Horses (IOI15_horses) C++14
0 / 100
1500 ms 43732 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int pot=1<<19,N=500007;

ll pw(ll a,int b)
{
    ll res=1;
    while(b)
    {
        if(b%2) res=res*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return res;
}

int seg[2*pot+7];

void ins(int v,int x)
{
    v+=pot-1;
    seg[v]=x;
    while(v>1)
    {
        v/=2;
        seg[v]=max(seg[2*v],seg[2*v+1]);
    }
}
int que(int v,int a,int b,int l,int r)
{
    if(a<=l&&b>=r) return seg[v];
    if(r<a||l>b) return 0;
    return max(que(2*v,a,b,l,(l+r)/2),que(2*v+1,a,b,(l+r)/2+1,r));
}
set<int>S;

ll inv[N],x[N];
ll T=1;

ll get()
{
    ll W=T,p=1;
    vector<int>V;
    for(auto i:S)
    {
       // if(p>1000000000) break;
        W=W*inv[-i]%mod;
        p=p*x[-i];
        V.pb(-i);
    }
    reverse(all(V));
    __int128 ans=0,t=1;
    for(auto i:V)
    {
        //cout<<i<<" "<<que(1,i,pot,1,pot)<<endl;
        t=t*x[i];
        ans=max(ans,t*(__int128)que(1,i,pot,1,pot));
    }
    return ans%mod*W%mod;
}

int init(int n,int X[],int Y[])
{
    for(int i=0;i<n;i++) seg[i+pot]=Y[i];
    for(int i=pot-1;i>0;i--) seg[i]=max(seg[2*i],seg[2*i+1]);
    for(int i=0;i<n;i++)
    {
        T=T*X[i]%mod;
        x[i+1]=X[i];
        inv[i+1]=pw(X[i],mod-2);
        if(X[i]>1) S.insert(-(i+1));
    }
    return get();
}


int updateX(int i,int v)
{
    i++;
    T=T*inv[i]%mod;
    S.erase(-i);
    T=T*(ll)v%mod;
    inv[i]=pw(v,mod-2);
    if(v>1) S.insert(-i);
    x[i]=v;
    return get();
}

int updateY(int i,int v)
{
    i++;
    ins(i,v);
    return get();
}

/*
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<init(3,{2,1,3},{3,4,1})<<endl;
    cout<<updateY(1,2)<<endl;


    return 0;
}*/

Compilation message

horses.cpp: In function 'long long int get()':
horses.cpp:73:21: warning: conversion from '__int128' to 'long long int' may change value [-Wconversion]
   73 |     return ans%mod*W%mod;
      |            ~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:84:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   84 |         inv[i+1]=pw(X[i],mod-2);
      |                          ~~~^~
horses.cpp:87:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   87 |     return get();
      |            ~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:97:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   97 |     inv[i]=pw(v,mod-2);
      |                 ~~~^~
horses.cpp:100:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  100 |     return get();
      |            ~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:107:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  107 |     return get();
      |            ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Incorrect 2 ms 2260 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Incorrect 2 ms 2260 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1570 ms 43732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Incorrect 2 ms 2260 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Incorrect 2 ms 2260 KB Output isn't correct
6 Halted 0 ms 0 KB -