Submission #988999

# Submission time Handle Problem Language Result Execution time Memory
988999 2024-05-27T09:46:51 Z tosivanmak Horses (IOI15_horses) C++17
100 / 100
843 ms 88364 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const __int128 MOD=1e9+7;

 
// TODO: global variables can be declared here
struct SEG{
    vector<ll>seg,arr;
    void init(ll n){
        seg.resize(4*n+5),arr.resize(n+5);
    }
    void build(ll l, ll r, ll id){
        if(l==r){
            seg[id]=arr[l];
        }
        else{
            ll mid=(l+r)>>1;
            build(l,mid,id*2),build(mid+1,r,id*2+1);
            seg[id]=max(seg[id*2],seg[id*2+1]);
        }
    }
    void upd(ll ul, ll l, ll r, ll val, ll id){
        if(l==r){
            seg[id]=val;
        }
        else{
            ll mid=(l+r)>>1;
            if(ul<=mid)upd(ul,l,mid,val,id*2);
            else upd(ul,mid+1,r,val,id*2+1);
            seg[id]=max(seg[id*2],seg[id*2+1]);
        }
    }
    ll qry(ll ql, ll qr, ll l, ll r, ll id){
        if(l>qr||r<ql){
            return -1e18;
        }
        if(l>=ql&&r<=qr)return seg[id];
        ll mid=(l+r)>>1;
        return max(qry(ql,qr,l,mid,id*2),qry(ql,qr,mid+1,r,id*2+1));
    }
}st;
struct MULTIPLICATION{
    vector<ll>seg,arr;
    void init(ll n){
        seg.resize(4*n+5),arr.resize(n+5);
    }
    void build(ll l, ll r, ll id){
        if(l==r){
            seg[id]=arr[l]%MOD;
        }
        else{
            ll mid=(l+r)>>1;
            build(l,mid,id*2),build(mid+1,r,id*2+1);
            seg[id]=seg[id*2]*seg[id*2+1];
            seg[id]%=MOD;
        }
    }
    void upd(ll ul, ll l, ll r, ll val, ll id){
        if(l==r){
            seg[id]=val;
            seg[id]%=MOD;
        }
        else{
            ll mid=(l+r)>>1;
            if(ul<=mid)upd(ul,l,mid,val,id*2);
            else upd(ul,mid+1,r,val,id*2+1);
            seg[id]=seg[id*2]*seg[id*2+1];
            seg[id]%=MOD;
        }
    }
    ll qry(ll ql, ll qr, ll l, ll r, ll id){
        if(l>qr||r<ql){
            return 1;
        }
        if(l>=ql&&r<=qr)return seg[id];
        ll mid=(l+r)>>1;
        return (qry(ql,qr,l,mid,id*2)*qry(ql,qr,mid+1,r,id*2+1)%MOD);
    }
}mul;
vector<ll>qry;
set<ll>ms;
vector<ll>x,y;
ll n;
 
 
ll func(){
    __int128 m=1;
    for(ll u: ms){
        if(m>MOD){break;}
        m*=x[-u];
            qry.push_back(-u);
    }
    ll ans; __int128 maxi=-1e18;
    bool ok=0;
    if(m<=MOD){
        ans=st.qry(1,n,1,n,1);
       ok=1;
    }
    reverse(qry.begin(),qry.end());
    m=1;
    for(int i=0;i<qry.size();i++){
        m*=x[qry[i]];
        __int128 mu;
        if(i==qry.size()-1)mu=st.qry(qry[i],n,1,n,1);
        else mu=st.qry(qry[i],qry[i+1]-1,1,n,1);
        if(mu*m>maxi){
            maxi=mu*m;
            ll store=mu%MOD;
            if(!ok){
                ans=mul.qry(1,qry[i],1,n,1)*store%MOD;
            }
            else{
                ans=max(ans,mul.qry(1,qry[i],1,n,1)*store);
            }
        }
    }
    qry.clear();
    return ans%MOD;
}
int init(int N, int X[], int Y[]) {
  // TODO: implementation
  n=N;
    st.init(N);mul.init(n);
    x.push_back(0),y.push_back(0);
    for(int i=0;i<n;i++){
        x.push_back(X[i]);
        y.push_back(Y[i]);
    }
    for(int i=1;i<=n;i++){
        st.arr[i]=y[i];
        mul.arr[i]=x[i];
    }
    st.build(1,n,1),mul.build(1,n,1);
    for(int i=1;i<=n;i++){
        if(x[i]!=1){
            ms.insert(-i);
        }
    }
    return func();
}
 
int updateX(int pos, int val) {
  // TODO: implementation
  pos++;
  if(x[pos]!=1){
      ms.erase(-pos);
  }
  x[pos]=val;
  mul.upd(pos,1,n,val,1);
  if(x[pos]!=1)ms.insert(-pos);
  return func();
}
 
int updateY(int pos, int val) {
  // TODO: implementation
  pos++;
    y[pos]=val;
  st.upd(pos,1,n,val,1);
  return func();
}

Compilation message

horses.cpp: In function 'long long int func()':
horses.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for(int i=0;i<qry.size();i++){
      |                 ~^~~~~~~~~~~
horses.cpp:105:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |         if(i==qry.size()-1)mu=st.qry(qry[i],n,1,n,1);
      |            ~^~~~~~~~~~~~~~
horses.cpp:109:24: warning: conversion from '__int128' to 'long long int' may change value [-Wconversion]
  109 |             ll store=mu%MOD;
      |                      ~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:140:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  140 |     return func();
      |            ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:152:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  152 |   return func();
      |          ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:160:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  160 |   return func();
      |          ~~~~^~
horses.cpp: In function 'long long int func()':
horses.cpp:94:8: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   94 |     ll ans; __int128 maxi=-1e18;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 408 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 2 ms 576 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 382 ms 75784 KB Output is correct
2 Correct 261 ms 88364 KB Output is correct
3 Correct 290 ms 79592 KB Output is correct
4 Correct 360 ms 83372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 440 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 4 ms 344 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 3 ms 452 KB Output is correct
33 Correct 54 ms 55492 KB Output is correct
34 Correct 51 ms 55468 KB Output is correct
35 Correct 200 ms 85604 KB Output is correct
36 Correct 162 ms 85668 KB Output is correct
37 Correct 100 ms 53684 KB Output is correct
38 Correct 104 ms 66312 KB Output is correct
39 Correct 43 ms 53492 KB Output is correct
40 Correct 158 ms 80800 KB Output is correct
41 Correct 91 ms 53492 KB Output is correct
42 Correct 106 ms 53596 KB Output is correct
43 Correct 154 ms 81156 KB Output is correct
44 Correct 158 ms 81124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 404 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 628 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 410 ms 79380 KB Output is correct
34 Correct 288 ms 88144 KB Output is correct
35 Correct 344 ms 79460 KB Output is correct
36 Correct 401 ms 83408 KB Output is correct
37 Correct 75 ms 55396 KB Output is correct
38 Correct 52 ms 55556 KB Output is correct
39 Correct 174 ms 85608 KB Output is correct
40 Correct 201 ms 85552 KB Output is correct
41 Correct 112 ms 53624 KB Output is correct
42 Correct 129 ms 66172 KB Output is correct
43 Correct 73 ms 53564 KB Output is correct
44 Correct 159 ms 80728 KB Output is correct
45 Correct 76 ms 53488 KB Output is correct
46 Correct 106 ms 53680 KB Output is correct
47 Correct 179 ms 81068 KB Output is correct
48 Correct 171 ms 81032 KB Output is correct
49 Correct 159 ms 58272 KB Output is correct
50 Correct 126 ms 58276 KB Output is correct
51 Correct 263 ms 87512 KB Output is correct
52 Correct 220 ms 86944 KB Output is correct
53 Correct 843 ms 56608 KB Output is correct
54 Correct 382 ms 70112 KB Output is correct
55 Correct 117 ms 54692 KB Output is correct
56 Correct 241 ms 82588 KB Output is correct
57 Correct 439 ms 55212 KB Output is correct
58 Correct 629 ms 55700 KB Output is correct
59 Correct 153 ms 81068 KB Output is correct