답안 #726928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726928 2023-04-19T15:16:45 Z Yell0 말 (IOI15_horses) C++17
54 / 100
1500 ms 29488 KB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll modinv(ll a) {
  ll res=1;
  for(ll i=0;(1LL<<i)<=MOD-2;++i) {
    if((MOD-2)&(1LL<<i)) res=res*a%MOD;
    a=a*a%MOD;
  }
  return res;
}

int N;
vector<ll> bit,X,Y;
void upd(int i,int a) {
  for(;i<=N;i+=-i&i) bit[i]=bit[i]*a%MOD;
}
ll qry(int i) {
  ll res=1;
  for(;i>0;i-=-i&i) res=res*bit[i]%MOD;
  return res;
}

int init(int n,int x[],int y[]) {
  N=n;
  bit.resize(N+2,1);
  X.resize(N+2,1);
  Y.resize(N+2,1);
  for(int i=1;i<=N;++i) {
    upd(i,x[i-1]);
    X[i]=x[i-1];
    Y[i]=y[i-1];
  }
  ll pfx=1,sfx=1,mpfx=1;
  int mxi,sti=N;
  for(int i=N;i>0;--i) {
    sfx*=X[i];
    sti=i;
    if(sfx>=(ll)1e9) break;
  }
  mxi=sti;
  for(int i=sti;i<=N;++i) {
    pfx*=X[i];
    if(pfx/mpfx>Y[mxi]/Y[i]) {
      mxi=i;
      mpfx=pfx;
    }
  }
  return qry(mxi)*Y[mxi]%MOD;
}
int updateX(int i,int a) {
  ++i;
  upd(i,modinv(X[i])*a%MOD);
  X[i]=a;
  ll pfx=1,sfx=1,mpfx=1;
  int mxi,sti=N;
  for(int i=N;i>0;--i) {
    sfx*=X[i];
    sti=i;
    if(sfx>=(ll)1e9) break;
  }
  mxi=sti;
  for(int i=sti;i<=N;++i) {
    pfx*=X[i];
    if(pfx/mpfx>Y[mxi]/Y[i]) {
      mxi=i;
      mpfx=pfx;
    }
  }
  return qry(mxi)*Y[mxi]%MOD;
}
int updateY(int i,int a) {
  ++i;
  Y[i]=a;
  ll pfx=1,sfx=1,mpfx=1;
  int mxi,sti=N;
  for(int i=N;i>0;--i) {
    sfx*=X[i];
    sti=i;
    if(sfx>=(ll)1e9) break;
  }
  mxi=sti;
  for(int i=sti;i<=N;++i) {
    pfx*=X[i];
    if(pfx/mpfx>Y[mxi]/Y[i]) {
      mxi=i;
      mpfx=pfx;
    }
  }
  return qry(mxi)*Y[mxi]%MOD;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:51:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   51 |   return qry(mxi)*Y[mxi]%MOD;
      |          ~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:55:23: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   55 |   upd(i,modinv(X[i])*a%MOD);
      |         ~~~~~~~~~~~~~~^~~~
horses.cpp:59:11: warning: declaration of 'int i' shadows a parameter [-Wshadow]
   59 |   for(int i=N;i>0;--i) {
      |           ^
horses.cpp:53:17: note: shadowed declaration is here
   53 | int updateX(int i,int a) {
      |             ~~~~^
horses.cpp:65:11: warning: declaration of 'int i' shadows a parameter [-Wshadow]
   65 |   for(int i=sti;i<=N;++i) {
      |           ^
horses.cpp:53:17: note: shadowed declaration is here
   53 | int updateX(int i,int a) {
      |             ~~~~^
horses.cpp:72:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   72 |   return qry(mxi)*Y[mxi]%MOD;
      |          ~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:79:11: warning: declaration of 'int i' shadows a parameter [-Wshadow]
   79 |   for(int i=N;i>0;--i) {
      |           ^
horses.cpp:74:17: note: shadowed declaration is here
   74 | int updateY(int i,int a) {
      |             ~~~~^
horses.cpp:85:11: warning: declaration of 'int i' shadows a parameter [-Wshadow]
   85 |   for(int i=sti;i<=N;++i) {
      |           ^
horses.cpp:74:17: note: shadowed declaration is here
   74 | int updateY(int i,int a) {
      |             ~~~~^
horses.cpp:92:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   92 |   return qry(mxi)*Y[mxi]%MOD;
      |          ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 11 ms 344 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 15 ms 340 KB Output is correct
32 Correct 9 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 16844 KB Output is correct
2 Correct 94 ms 16924 KB Output is correct
3 Correct 73 ms 16864 KB Output is correct
4 Correct 95 ms 16836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 11 ms 340 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 14 ms 344 KB Output is correct
32 Correct 9 ms 340 KB Output is correct
33 Correct 349 ms 19976 KB Output is correct
34 Correct 40 ms 19916 KB Output is correct
35 Correct 74 ms 26980 KB Output is correct
36 Correct 69 ms 26816 KB Output is correct
37 Execution timed out 1548 ms 18056 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 12 ms 344 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 15 ms 352 KB Output is correct
32 Correct 9 ms 340 KB Output is correct
33 Correct 101 ms 20656 KB Output is correct
34 Correct 100 ms 29488 KB Output is correct
35 Correct 68 ms 20712 KB Output is correct
36 Correct 97 ms 24588 KB Output is correct
37 Correct 342 ms 19964 KB Output is correct
38 Correct 41 ms 19920 KB Output is correct
39 Correct 71 ms 26792 KB Output is correct
40 Correct 69 ms 26740 KB Output is correct
41 Execution timed out 1563 ms 18056 KB Time limit exceeded
42 Halted 0 ms 0 KB -