Submission #785657

# Submission time Handle Problem Language Result Execution time Memory
785657 2023-07-17T11:30:54 Z I_Love_EliskaM_ Horses (IOI15_horses) C++14
100 / 100
425 ms 41276 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
const int mod = 1e9+7;

#define int long long
int pw(int a, int b) {
  int r=1;
  while (b) {
    if (b&1) r=(r*a)%mod;
    a=(a*a)%mod;
    b>>=1;
  }
  return r;
}
int inv(int x) {
  return pw(x,mod-2);
}

struct BIT {
  vector<int> t; int n;
  BIT(int n) {
    this->n=n;
    t.assign(n,1);
  }
  void add(int i, int x) {
    for(;i<n;i=i|(i+1)) t[i]=(t[i]*x)%mod;
  }
  int sum(int r) {
    int q=1;
    for(;r>=0;r=(r&(r+1))-1) q=(q*t[r])%mod;
    return q;
  }
};
#undef int

int a[(int)5e5+5];
int c[(int)5e5+5];
BIT ft(5e5+5);
set<int> s;
int n;

struct sgt {
  vector<int> t; int sz=1;
  sgt(int n) {
    while (sz<n) sz<<=1;
    t.assign(2*sz,0);
  }
  int query(int v, int l, int r, int lx, int rx) {
    if (rx<=l || r<=lx) return 0;
    if (lx<=l && r<=rx) return t[v];
    int m=(l+r)>>1;
    int lq=query(2*v+1,l,m,lx,rx);
    int rq=query(2*v+2,m,r,lx,rx);
    return max(lq,rq);
  }
  int query(int l, int r) {
    return query(0,0,sz,l,r);
  }

  void upd(int v, int l, int r, int i) {
    if (r-l==1) return;
    int m=(l+r)>>1;
    if (i<m) upd(2*v+1,l,m,i);
    else upd(2*v+2,m,r,i);
    t[v]=max(t[2*v+1],t[2*v+2]);
  }
  void set(int i, int x) {
    t[sz-1+i]=x;
    upd(0,0,sz,i);
  }
};
sgt st(5e5+5);

int query() {
  #define int long long
  int z=1;
  int b=0;
  pi mx={0,1};
  int last=n;
  s.insert(0);
  for (auto v:s) {
    int i=-v;
    if (z>1e9) break;
    int y=st.query(i,n);
    if (y*mx.s>mx.f*z) {
      b=i;
      mx={y,z};
    }
    z*=a[i];
    last=i;
  }
  int p=ft.sum(b);
  int y=st.query(b,n);
  return (p*y)%mod;
  #undef int
}

int init(int _n, int x[], int y[]) { 
  n=_n;
  forn(i,n) a[i]=x[i], c[i]=y[i];
  forn(i,n) ft.add(i,a[i]);
  forn(i,n) if (a[i]>1) s.insert(-i);
  forn(i,n) st.set(i,c[i]);
  return query();
}
int updateX(int i, int x) {
  if (a[i]>1) s.erase(s.find(-i));
  ft.add(i,inv(a[i]));
  a[i]=x;
  if (a[i]>1) s.insert(-i);
  ft.add(i,a[i]);
  return query();
}
int updateY(int i, int x) {
  c[i]=x;
  st.set(i,c[i]);
  return query();
}

Compilation message

horses.cpp: In constructor 'BIT::BIT(long long int)':
horses.cpp:28:11: warning: declaration of 'n' shadows a member of 'BIT' [-Wshadow]
   28 |   BIT(int n) {
      |           ^
horses.cpp:27:22: note: shadowed declaration is here
   27 |   vector<int> t; int n;
      |                      ^
horses.cpp: In constructor 'BIT::BIT(long long int)':
horses.cpp:28:11: warning: declaration of 'n' shadows a member of 'BIT' [-Wshadow]
   28 |   BIT(int n) {
      |           ^
horses.cpp:27:22: note: shadowed declaration is here
   27 |   vector<int> t; int n;
      |                      ^
horses.cpp: In constructor 'BIT::BIT(long long int)':
horses.cpp:28:11: warning: declaration of 'n' shadows a member of 'BIT' [-Wshadow]
   28 |   BIT(int n) {
      |           ^
horses.cpp:27:22: note: shadowed declaration is here
   27 |   vector<int> t; int n;
      |                      ^
horses.cpp: In constructor 'sgt::sgt(int)':
horses.cpp:51:11: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   51 |   sgt(int n) {
      |       ~~~~^
horses.cpp:47:5: note: shadowed declaration is here
   47 | int n;
      |     ^
horses.cpp: In constructor 'sgt::sgt(int)':
horses.cpp:51:11: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   51 |   sgt(int n) {
      |       ~~~~^
horses.cpp:47:5: note: shadowed declaration is here
   47 | int n;
      |     ^
horses.cpp: In constructor 'sgt::sgt(int)':
horses.cpp:51:11: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   51 |   sgt(int n) {
      |       ~~~~^
horses.cpp:47:5: note: shadowed declaration is here
   47 | int n;
      |     ^
horses.cpp: In function 'int query()':
horses.cpp:90:9: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   90 |     if (z>1e9) break;
      |         ^
horses.cpp:91:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   91 |     int y=st.query(i,n);
      |                    ^
horses.cpp:100:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  100 |   int y=st.query(b,n);
      |                  ^
horses.cpp:101:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  101 |   return (p*y)%mod;
      |          ~~~~~^~~~
horses.cpp:86:7: warning: variable 'last' set but not used [-Wunused-but-set-variable]
   86 |   int last=n;
      |       ^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8276 KB Output is correct
2 Correct 4 ms 8348 KB Output is correct
3 Correct 4 ms 8404 KB Output is correct
4 Correct 5 ms 8276 KB Output is correct
5 Correct 4 ms 8276 KB Output is correct
6 Correct 4 ms 8348 KB Output is correct
7 Correct 4 ms 8276 KB Output is correct
8 Correct 4 ms 8348 KB Output is correct
9 Correct 4 ms 8348 KB Output is correct
10 Correct 4 ms 8276 KB Output is correct
11 Correct 5 ms 8276 KB Output is correct
12 Correct 4 ms 8352 KB Output is correct
13 Correct 4 ms 8344 KB Output is correct
14 Correct 3 ms 8344 KB Output is correct
15 Correct 4 ms 8276 KB Output is correct
16 Correct 4 ms 8276 KB Output is correct
17 Correct 4 ms 8276 KB Output is correct
18 Correct 4 ms 8344 KB Output is correct
19 Correct 4 ms 8348 KB Output is correct
20 Correct 4 ms 8352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8276 KB Output is correct
2 Correct 3 ms 8276 KB Output is correct
3 Correct 5 ms 8348 KB Output is correct
4 Correct 4 ms 8348 KB Output is correct
5 Correct 4 ms 8276 KB Output is correct
6 Correct 4 ms 8276 KB Output is correct
7 Correct 4 ms 8276 KB Output is correct
8 Correct 4 ms 8276 KB Output is correct
9 Correct 4 ms 8276 KB Output is correct
10 Correct 4 ms 8276 KB Output is correct
11 Correct 3 ms 8340 KB Output is correct
12 Correct 4 ms 8276 KB Output is correct
13 Correct 4 ms 8276 KB Output is correct
14 Correct 4 ms 8348 KB Output is correct
15 Correct 4 ms 8276 KB Output is correct
16 Correct 4 ms 8348 KB Output is correct
17 Correct 4 ms 8276 KB Output is correct
18 Correct 4 ms 8276 KB Output is correct
19 Correct 4 ms 8232 KB Output is correct
20 Correct 4 ms 8276 KB Output is correct
21 Correct 4 ms 8344 KB Output is correct
22 Correct 4 ms 8276 KB Output is correct
23 Correct 4 ms 8404 KB Output is correct
24 Correct 4 ms 8404 KB Output is correct
25 Correct 5 ms 8404 KB Output is correct
26 Correct 5 ms 8356 KB Output is correct
27 Correct 7 ms 8276 KB Output is correct
28 Correct 5 ms 8404 KB Output is correct
29 Correct 4 ms 8352 KB Output is correct
30 Correct 7 ms 8404 KB Output is correct
31 Correct 6 ms 8288 KB Output is correct
32 Correct 6 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 41208 KB Output is correct
2 Correct 302 ms 41212 KB Output is correct
3 Correct 319 ms 41236 KB Output is correct
4 Correct 346 ms 41276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8276 KB Output is correct
2 Correct 4 ms 8352 KB Output is correct
3 Correct 4 ms 8348 KB Output is correct
4 Correct 3 ms 8344 KB Output is correct
5 Correct 4 ms 8276 KB Output is correct
6 Correct 3 ms 8276 KB Output is correct
7 Correct 4 ms 8340 KB Output is correct
8 Correct 4 ms 8276 KB Output is correct
9 Correct 4 ms 8352 KB Output is correct
10 Correct 4 ms 8276 KB Output is correct
11 Correct 4 ms 8280 KB Output is correct
12 Correct 4 ms 8276 KB Output is correct
13 Correct 4 ms 8344 KB Output is correct
14 Correct 5 ms 8352 KB Output is correct
15 Correct 5 ms 8264 KB Output is correct
16 Correct 5 ms 8276 KB Output is correct
17 Correct 4 ms 8348 KB Output is correct
18 Correct 4 ms 8276 KB Output is correct
19 Correct 4 ms 8344 KB Output is correct
20 Correct 4 ms 8344 KB Output is correct
21 Correct 4 ms 8276 KB Output is correct
22 Correct 4 ms 8276 KB Output is correct
23 Correct 4 ms 8404 KB Output is correct
24 Correct 4 ms 8404 KB Output is correct
25 Correct 5 ms 8460 KB Output is correct
26 Correct 5 ms 8356 KB Output is correct
27 Correct 7 ms 8404 KB Output is correct
28 Correct 5 ms 8404 KB Output is correct
29 Correct 4 ms 8276 KB Output is correct
30 Correct 5 ms 8404 KB Output is correct
31 Correct 6 ms 8360 KB Output is correct
32 Correct 6 ms 8356 KB Output is correct
33 Correct 77 ms 16924 KB Output is correct
34 Correct 77 ms 16916 KB Output is correct
35 Correct 183 ms 40276 KB Output is correct
36 Correct 180 ms 40284 KB Output is correct
37 Correct 95 ms 16972 KB Output is correct
38 Correct 115 ms 28832 KB Output is correct
39 Correct 65 ms 16796 KB Output is correct
40 Correct 166 ms 40296 KB Output is correct
41 Correct 72 ms 16848 KB Output is correct
42 Correct 80 ms 16788 KB Output is correct
43 Correct 163 ms 40300 KB Output is correct
44 Correct 159 ms 40240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8276 KB Output is correct
2 Correct 6 ms 8236 KB Output is correct
3 Correct 4 ms 8348 KB Output is correct
4 Correct 4 ms 8276 KB Output is correct
5 Correct 3 ms 8344 KB Output is correct
6 Correct 4 ms 8276 KB Output is correct
7 Correct 4 ms 8276 KB Output is correct
8 Correct 4 ms 8276 KB Output is correct
9 Correct 4 ms 8344 KB Output is correct
10 Correct 4 ms 8276 KB Output is correct
11 Correct 4 ms 8348 KB Output is correct
12 Correct 4 ms 8344 KB Output is correct
13 Correct 4 ms 8344 KB Output is correct
14 Correct 5 ms 8344 KB Output is correct
15 Correct 4 ms 8276 KB Output is correct
16 Correct 4 ms 8276 KB Output is correct
17 Correct 3 ms 8276 KB Output is correct
18 Correct 3 ms 8276 KB Output is correct
19 Correct 4 ms 8276 KB Output is correct
20 Correct 3 ms 8276 KB Output is correct
21 Correct 3 ms 8276 KB Output is correct
22 Correct 4 ms 8276 KB Output is correct
23 Correct 5 ms 8360 KB Output is correct
24 Correct 4 ms 8404 KB Output is correct
25 Correct 5 ms 8404 KB Output is correct
26 Correct 4 ms 8404 KB Output is correct
27 Correct 7 ms 8404 KB Output is correct
28 Correct 7 ms 8424 KB Output is correct
29 Correct 4 ms 8276 KB Output is correct
30 Correct 4 ms 8360 KB Output is correct
31 Correct 6 ms 8276 KB Output is correct
32 Correct 6 ms 8276 KB Output is correct
33 Correct 376 ms 41184 KB Output is correct
34 Correct 310 ms 41184 KB Output is correct
35 Correct 282 ms 41152 KB Output is correct
36 Correct 331 ms 41192 KB Output is correct
37 Correct 74 ms 16972 KB Output is correct
38 Correct 74 ms 16920 KB Output is correct
39 Correct 186 ms 40284 KB Output is correct
40 Correct 185 ms 40284 KB Output is correct
41 Correct 105 ms 16912 KB Output is correct
42 Correct 123 ms 28776 KB Output is correct
43 Correct 66 ms 16788 KB Output is correct
44 Correct 165 ms 40268 KB Output is correct
45 Correct 76 ms 16960 KB Output is correct
46 Correct 81 ms 16796 KB Output is correct
47 Correct 187 ms 40172 KB Output is correct
48 Correct 160 ms 40156 KB Output is correct
49 Correct 165 ms 18896 KB Output is correct
50 Correct 165 ms 18840 KB Output is correct
51 Correct 300 ms 41164 KB Output is correct
52 Correct 258 ms 41168 KB Output is correct
53 Correct 425 ms 18832 KB Output is correct
54 Correct 246 ms 31736 KB Output is correct
55 Correct 146 ms 16896 KB Output is correct
56 Correct 261 ms 41164 KB Output is correct
57 Correct 232 ms 17724 KB Output is correct
58 Correct 308 ms 17760 KB Output is correct
59 Correct 182 ms 40220 KB Output is correct