Submission #590075

# Submission time Handle Problem Language Result Execution time Memory
590075 2022-07-05T14:00:15 Z alirezasamimi100 Horses (IOI15_horses) C++17
100 / 100
674 ms 57268 KB
#include "horses.h"
#include <bits/stdc++.h>
#define lc v<<1
#define rc v<<1|1
using ll = long long int;
using namespace std;
const int MOD = 1000000007, MN = 5e5 + 10;

ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}

ll f[MN*4],g[MN],RX[MN];
int n;
set<int> st;

void update(int v, int l, int r, int p, ll x){
    if(r-l==1){
        f[v]=x;
        return;
    }
    int m=(l+r)>>1;
    if(p<m) update(lc,l,m,p,x);
    else update(rc,m,r,p,x);
    f[v]=max(f[lc],f[rc]);
}

ll get(int v, int l, int r, int tl, int tr){
    if(l>=tr || tl>=r || tl>=tr) return 0;
    if(l>=tl && r<=tr) return f[v];
    int m=(l+r)>>1;
    return max(get(lc,l,m,tl,tr),get(rc,m,r,tl,tr));
}

void upd(int t, ll x){
    for(t+=5; t<MN; t+=t&-t) g[t]=g[t]*x%MOD;
}

ll gt(int t, ll x=1){
    for(t+=5; t; t-=t&-t) x=x*g[t]%MOD;
    return x;
}

int init(int N, int X[], int Y[]) {
    n=N;
    for(ll i=0; i<MN; i++) g[i]=1;
    for(int i=0; i<N; i++){
        update(1,0,n,i,Y[i]);
        upd(i,X[i]);
        RX[i]=X[i];
        if(X[i]>1) st.insert(-i);
    }
    ll ans=0,k=-1;
    for(int t : st){
        if(ans>(ll)1e9) break;
        t=-t;
        k=t;
        ans=max(ans,get(1,0,n,t,n));
        ans*=RX[t];
    }
    if(f[1]>ans) ans=f[1];
    else ans=ans%MOD*gt(k-1)%MOD;
    return ans;
}

int updateX(int pos, int val) {
    ll x=pow(RX[pos],MOD-2,MOD)*val%MOD;
    upd(pos,x);
    RX[pos]=val;
    if(val>1) st.insert(-pos);
    else st.erase(-pos);
    ll ans=0,k=-1;
    for(int t : st){
        if(ans>(ll)1e9) break;
        t=-t;
        k=t;
        ans=max(ans,get(1,0,n,t,n));
        ans*=RX[t];
    }
    if(f[1]>ans) ans=f[1];
    else ans=ans%MOD*gt(k-1)%MOD;
    return ans;
}

int updateY(int pos, int val) {
    update(1,0,n,pos,val);
    ll ans=0,k=-1;
    for(int t : st){
        if(ans>(ll)1e9) break;
        t=-t;
        k=t;
        ans=max(ans,get(1,0,n,t,n));
        ans*=RX[t];
    }
    if(f[1]>ans) ans=f[1];
    else ans=ans%MOD*gt(k-1)%MOD;
    return ans;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:68:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   68 |     else ans=ans%MOD*gt(k-1)%MOD;
      |                         ~^~
horses.cpp:69:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   69 |     return ans;
      |            ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:87:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   87 |     else ans=ans%MOD*gt(k-1)%MOD;
      |                         ~^~
horses.cpp:88:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   88 |     return ans;
      |            ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:102:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  102 |     else ans=ans%MOD*gt(k-1)%MOD;
      |                         ~^~
horses.cpp:103:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  103 |     return ans;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4120 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 3 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 3 ms 4132 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 3 ms 4204 KB Output is correct
13 Correct 3 ms 4180 KB Output is correct
14 Correct 2 ms 4180 KB Output is correct
15 Correct 3 ms 4152 KB Output is correct
16 Correct 3 ms 4180 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 3 ms 4180 KB Output is correct
20 Correct 3 ms 4152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Correct 2 ms 4148 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 3 ms 4184 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 3 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 2 ms 4148 KB Output is correct
11 Correct 2 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 3 ms 4156 KB Output is correct
14 Correct 4 ms 4180 KB Output is correct
15 Correct 4 ms 4180 KB Output is correct
16 Correct 2 ms 4132 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 3 ms 4180 KB Output is correct
19 Correct 2 ms 4180 KB Output is correct
20 Correct 3 ms 4180 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 2 ms 4180 KB Output is correct
23 Correct 4 ms 4308 KB Output is correct
24 Correct 3 ms 4292 KB Output is correct
25 Correct 4 ms 4316 KB Output is correct
26 Correct 4 ms 4308 KB Output is correct
27 Correct 5 ms 4180 KB Output is correct
28 Correct 5 ms 4308 KB Output is correct
29 Correct 4 ms 4184 KB Output is correct
30 Correct 3 ms 4304 KB Output is correct
31 Correct 4 ms 4180 KB Output is correct
32 Correct 7 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 674 ms 48512 KB Output is correct
2 Correct 386 ms 51056 KB Output is correct
3 Correct 380 ms 48472 KB Output is correct
4 Correct 443 ms 51500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 3 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 3 ms 4152 KB Output is correct
13 Correct 2 ms 4180 KB Output is correct
14 Correct 2 ms 4180 KB Output is correct
15 Correct 4 ms 4152 KB Output is correct
16 Correct 3 ms 4180 KB Output is correct
17 Correct 2 ms 4180 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 2 ms 4180 KB Output is correct
20 Correct 2 ms 4180 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 2 ms 4180 KB Output is correct
23 Correct 3 ms 4288 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 3 ms 4308 KB Output is correct
27 Correct 4 ms 4180 KB Output is correct
28 Correct 4 ms 4308 KB Output is correct
29 Correct 4 ms 4180 KB Output is correct
30 Correct 3 ms 4308 KB Output is correct
31 Correct 4 ms 4180 KB Output is correct
32 Correct 5 ms 4292 KB Output is correct
33 Correct 109 ms 24380 KB Output is correct
34 Correct 124 ms 24328 KB Output is correct
35 Correct 301 ms 54708 KB Output is correct
36 Correct 261 ms 54612 KB Output is correct
37 Correct 160 ms 22460 KB Output is correct
38 Correct 178 ms 35312 KB Output is correct
39 Correct 123 ms 22284 KB Output is correct
40 Correct 226 ms 49676 KB Output is correct
41 Correct 175 ms 22356 KB Output is correct
42 Correct 138 ms 22408 KB Output is correct
43 Correct 234 ms 50068 KB Output is correct
44 Correct 233 ms 50064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4160 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 2 ms 4152 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 2 ms 4152 KB Output is correct
13 Correct 2 ms 4180 KB Output is correct
14 Correct 4 ms 4180 KB Output is correct
15 Correct 3 ms 4180 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 2 ms 4180 KB Output is correct
18 Correct 3 ms 4156 KB Output is correct
19 Correct 3 ms 4224 KB Output is correct
20 Correct 4 ms 4152 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 2 ms 4180 KB Output is correct
23 Correct 4 ms 4308 KB Output is correct
24 Correct 4 ms 4292 KB Output is correct
25 Correct 5 ms 4308 KB Output is correct
26 Correct 3 ms 4284 KB Output is correct
27 Correct 5 ms 4180 KB Output is correct
28 Correct 5 ms 4308 KB Output is correct
29 Correct 3 ms 4180 KB Output is correct
30 Correct 4 ms 4308 KB Output is correct
31 Correct 4 ms 4296 KB Output is correct
32 Correct 4 ms 4180 KB Output is correct
33 Correct 581 ms 48500 KB Output is correct
34 Correct 356 ms 57268 KB Output is correct
35 Correct 354 ms 48548 KB Output is correct
36 Correct 376 ms 52484 KB Output is correct
37 Correct 107 ms 24332 KB Output is correct
38 Correct 104 ms 24336 KB Output is correct
39 Correct 269 ms 54696 KB Output is correct
40 Correct 241 ms 54692 KB Output is correct
41 Correct 134 ms 22476 KB Output is correct
42 Correct 166 ms 35248 KB Output is correct
43 Correct 96 ms 22300 KB Output is correct
44 Correct 218 ms 49680 KB Output is correct
45 Correct 143 ms 22332 KB Output is correct
46 Correct 132 ms 22408 KB Output is correct
47 Correct 204 ms 50120 KB Output is correct
48 Correct 208 ms 50036 KB Output is correct
49 Correct 196 ms 27408 KB Output is correct
50 Correct 169 ms 27420 KB Output is correct
51 Correct 364 ms 56536 KB Output is correct
52 Correct 285 ms 56088 KB Output is correct
53 Correct 594 ms 25668 KB Output is correct
54 Correct 309 ms 39324 KB Output is correct
55 Correct 149 ms 23312 KB Output is correct
56 Correct 284 ms 51560 KB Output is correct
57 Correct 385 ms 23976 KB Output is correct
58 Correct 533 ms 24508 KB Output is correct
59 Correct 220 ms 50084 KB Output is correct