답안 #1018423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018423 2024-07-10T03:31:17 Z huutuan 말 (IOI15_horses) C++14
100 / 100
749 ms 64812 KB
#include "horses.h"

#include <bits/stdc++.h>

using namespace std;

#define int long long

struct SegmentTree{
   int n;
   vector<int> t;
   void init(int _n){
      n=_n;
      t.assign(4*n+1, 0);
   }
   void build(int k, int l, int r, int a[]){
      if (l==r){
         t[k]=a[l];
         return;
      }
      int mid=(l+r)>>1;
      build(k<<1, l, mid, a);
      build(k<<1|1, mid+1, r, a);
      t[k]=max(t[k<<1], t[k<<1|1]);
   }
   void update(int k, int l, int r, int pos, int val){
      if (l==r){
         t[k]=val;
         return;
      }
      int mid=(l+r)>>1;
      if (pos<=mid) update(k<<1, l, mid, pos, val);
      else update(k<<1|1, mid+1, r, pos, val);
      t[k]=max(t[k<<1], t[k<<1|1]);
   }
   int get(int k, int l, int r, int L, int R){
      if (r<L || R<l) return 0;
      if (L<=l && r<=R) return t[k];
      int mid=(l+r)>>1;
      return max(get(k<<1, l, mid, L, R), get(k<<1|1, mid+1, r, L, R));
   }
} st;

const int N=5e5+10, mod=1e9+7;

int binpow(int x, int y){
   int t=1;
   while (y){
      if (y&1) t=1ll*t*x%mod;
      x=1ll*x*x%mod;
      y>>=1;
   }
   return t;
}

set<int> pos;
int n, a[N], b[N];
int prod;

int solve(){
   vector<pair<long long, int>> v;
   int p=1;
   for (auto it=pos.rbegin(); it!=pos.rend(); ++it){
      v.emplace_back(0, *it);
      if (a[*it]>=(mod+p-1)/p) break;
      p*=a[*it];
   }
   reverse(v.begin(), v.end());
   int ans=prod;
   int cur=1;
   for (int i=0; i<(int)v.size(); ++i){
      if (i) ans=1ll*ans*binpow(a[v[i].second], mod-2)%mod;
      if (i) cur*=a[v[i].second];
      v[i].first=1ll*cur*st.get(1, 1, n, v[i].second, i+1==(int)v.size()?n:v[i+1].second-1);
   }
   auto opt=*max_element(v.begin(), v.end());
   return 1ll*ans*(opt.first%mod)%mod;
}

int32_t init(int32_t _N, int32_t X[], int32_t Y[]) {
   n=_N;
   st.init(n);
   prod=1;
   for (int i=1; i<=n; ++i){
      a[i]=X[i-1], b[i]=Y[i-1];
      if (a[i]!=1 || i==1) pos.insert(i);
      prod=1ll*prod*a[i]%mod;
   }
   st.build(1, 1, n, b);
   return solve();
}

int32_t updateX(int32_t i, int32_t val) {
   ++i;
   prod=1ll*prod*binpow(a[i], mod-2)%mod;
   prod=1ll*prod*val%mod;
   a[i]=val;
   pos.erase(i);
   if (a[i]!=1 || i==1) pos.insert(i);
   return solve();
}

int32_t updateY(int32_t i, int32_t val) {
   ++i;
   b[i]=val;
   st.update(1, 1, n, i, val);
   return solve();
}

Compilation message

horses.cpp: In function 'int32_t init(int32_t, int32_t*, int32_t*)':
horses.cpp:90:16: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   90 |    return solve();
      |           ~~~~~^~
horses.cpp: In function 'int32_t updateX(int32_t, int32_t)':
horses.cpp:100:16: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
  100 |    return solve();
      |           ~~~~~^~
horses.cpp: In function 'int32_t updateY(int32_t, int32_t)':
horses.cpp:107:16: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
  107 |    return solve();
      |           ~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2420 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 2528 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 6 ms 2396 KB Output is correct
28 Correct 3 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2392 KB Output is correct
31 Correct 4 ms 2396 KB Output is correct
32 Correct 6 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 729 ms 52292 KB Output is correct
2 Correct 246 ms 52308 KB Output is correct
3 Correct 276 ms 55888 KB Output is correct
4 Correct 361 ms 59736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 7 ms 2396 KB Output is correct
28 Correct 2 ms 2504 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2504 KB Output is correct
31 Correct 4 ms 2396 KB Output is correct
32 Correct 6 ms 2564 KB Output is correct
33 Correct 35 ms 31840 KB Output is correct
34 Correct 32 ms 31780 KB Output is correct
35 Correct 164 ms 62036 KB Output is correct
36 Correct 148 ms 62188 KB Output is correct
37 Correct 91 ms 30000 KB Output is correct
38 Correct 102 ms 42676 KB Output is correct
39 Correct 27 ms 29724 KB Output is correct
40 Correct 133 ms 57688 KB Output is correct
41 Correct 59 ms 29776 KB Output is correct
42 Correct 86 ms 29964 KB Output is correct
43 Correct 131 ms 57680 KB Output is correct
44 Correct 132 ms 57640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 6 ms 2396 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2648 KB Output is correct
31 Correct 4 ms 2396 KB Output is correct
32 Correct 6 ms 2396 KB Output is correct
33 Correct 697 ms 56152 KB Output is correct
34 Correct 255 ms 64812 KB Output is correct
35 Correct 269 ms 55892 KB Output is correct
36 Correct 309 ms 59864 KB Output is correct
37 Correct 33 ms 31836 KB Output is correct
38 Correct 32 ms 31828 KB Output is correct
39 Correct 160 ms 62164 KB Output is correct
40 Correct 149 ms 62032 KB Output is correct
41 Correct 95 ms 30032 KB Output is correct
42 Correct 89 ms 42708 KB Output is correct
43 Correct 26 ms 29780 KB Output is correct
44 Correct 143 ms 57148 KB Output is correct
45 Correct 62 ms 29788 KB Output is correct
46 Correct 79 ms 29780 KB Output is correct
47 Correct 131 ms 57684 KB Output is correct
48 Correct 127 ms 57680 KB Output is correct
49 Correct 124 ms 34896 KB Output is correct
50 Correct 104 ms 34896 KB Output is correct
51 Correct 313 ms 63932 KB Output is correct
52 Correct 209 ms 63572 KB Output is correct
53 Correct 749 ms 33424 KB Output is correct
54 Correct 296 ms 46676 KB Output is correct
55 Correct 105 ms 30804 KB Output is correct
56 Correct 193 ms 58960 KB Output is correct
57 Correct 442 ms 31572 KB Output is correct
58 Correct 618 ms 32080 KB Output is correct
59 Correct 133 ms 57680 KB Output is correct