Submission #387406

#TimeUsernameProblemLanguageResultExecution timeMemory
387406mehrdad_sohrabiHorses (IOI15_horses)C++14
0 / 100
774 ms44904 KiB
/// Black lives matter
#include <bits/stdc++.h>
#include "horses.h"
/// 500 485 462 A4
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
//#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=5e5+10;
ll seg[N*4];
set <int> s;
ll x[N],y[N];
ll n;
ll mod=1e9+7;
ll ans=1;
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
void upd(ll nod,ll l,ll r,ll id,ll val){
    if (r-l==1){
        seg[nod]=val;
        return ;
    }
    ll mid=(r+l)/2;
    if (mid>id) upd(nod*2,l,mid,id,val);
    else upd(nod*2+1,mid,r,id,val);
    seg[nod]=max(seg[nod*2],seg[nod*2+1]);
}
ll get(ll nod,ll l,ll r,ll L,ll R){
    if (l>=R || L>=r) return 0;
    if (l>=L && r<=R) return seg[nod];
    ll mid=(r+l)/2;
    return max( get(nod*2,l,mid,L,R), get(nod*2+1,mid,r,L,R));
}
int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
    n=N;
    for (int i=0;i<n;i++) {
        x[i]=X[i];
        y[i]=Y[i];
        upd(1,0,n,i,y[i]);
        if (x[i]>1) s.insert(i);
    //    cout << x[i] << endl;
        ans*=x[i];
        ans%=mod;
    }
   // cout << ans << " ans " << endl;
	return 0;
}
ll solve(){
    ll jav=ans;
    ll cnt=1;
    auto t=s.end();
    ll p1=0;
    for (int i=0;i<min((ll)s.size(),(ll)30);i++){
        t--;
        ll z=get(1,0,n,*t,n);
        if (z>cnt){
            jav=ans*power(cnt,mod-2)%mod*z%mod;
        }
        cnt*=x[*t];
        if (cnt>(ll)1e9){
            p1=1;
            break;
        }
    }
    if (p1==1){
        ll z=get(1,0,n,0,n);
        if (z>cnt) jav=z;
    }
    return jav;
}
int32_t updateX(int32_t pos, int32_t val) {
    ans=ans*power(x[pos],mod-2)%mod;
    ans*=val;
    ans%=mod;
    x[pos]=val;
    cout << ans << endl;
    if (x[pos]==1) s.erase(pos);
    else s.insert(pos);
	return solve();
}

int32_t updateY(int32_t pos, int32_t val) {
    y[pos]=val;
    upd(1,0,n,pos,val);
	return solve();
}
/*
int32_t X[N],Y[N];
int32_t main(){
    ll n;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> X[i];
    }
    for (int i=0;i<n;i++){
        cin >> Y[i];
    }
    init(n,X,Y);
   // cout << solve() << " solve " << endl;
    ll q;
    cin >> q;
    while(q--){
        ll ty;
        cin >> ty;
        ll pos,val;
        cin >> pos >> val;
        if (ty==1){
            cout << updateX(pos,val) << endl;
        }
        else cout << updateY(pos,val) << endl;;
    }
}
*/
/*
3
2 1 3
3 4 1
1
2 1 2
*/

Compilation message (stderr)

horses.cpp: In function 'll power(ll, ll)':
horses.cpp:25:19: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   25 | ll power(ll n,ll k){
      |                   ^
horses.cpp:22:4: note: shadowed declaration is here
   22 | ll n;
      |    ^
horses.cpp:28:12: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   28 |         ll x=power(n,k/2);
      |            ^
horses.cpp:21:4: note: shadowed declaration is here
   21 | ll x[N],y[N];
      |    ^
horses.cpp:31:8: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   31 |     ll x=power(n,k/2);
      |        ^
horses.cpp:21:4: note: shadowed declaration is here
   21 | ll x[N],y[N];
      |    ^
horses.cpp: In function 'int32_t init(int32_t, int32_t*, int32_t*)':
horses.cpp:50:49: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   50 | int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
      |                                                 ^
horses.cpp:18:11: note: shadowed declaration is here
   18 | const int N=5e5+10;
      |           ^
horses.cpp: In function 'int32_t updateX(int32_t, int32_t)':
horses.cpp:95:14: warning: conversion from 'll' {aka 'long long int'} to 'int32_t' {aka 'int'} may change value [-Wconversion]
   95 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int32_t updateY(int32_t, int32_t)':
horses.cpp:101:14: warning: conversion from 'll' {aka 'long long int'} to 'int32_t' {aka 'int'} may change value [-Wconversion]
  101 |  return solve();
      |         ~~~~~^~
#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...