#include "horses.h"
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<int(b); i++)
using namespace std;
int n;
long long x[500000],y[500000];
long long m=1e9+7;
pair<long long,long long> invgcd(long long a, long long b) {
//Returns x and y such that ax+by=1
if (a==1 && b==0) return make_pair(1,0);
long long c=a%b;
long long d=a/b;
pair<long long, long long > ans = invgcd(b,c);
return make_pair(ans.second,ans.first-ans.second*d);
}
long long inverse(long long a) {
pair<long long, long long > ans = invgcd(m,a);
return ans.second;
}
int init(int N, int X[], int Y[]) {
n=N;
rep (i,0,n) {
x[i]=X[i];
y[i]=Y[i];
}
long long product=1;
rep (i,0,n) {
product*=x[i];
product%=m;
}
long long hi=y[n-1];
long long divide=1;
for (int i = n-2; i<=0; i--) {
hi*=x[i+1];
hi=max(hi,y[i]);
divide*=x[i+1];
if (hi>1e9) break;
}
long long ans=hi*product;
ans%=m;
ans*=inverse(divide);
ans%=m;
return ans;
}
int updateX(int pos, int val) {
x[pos]=val;
long long product=1;
rep (i,0,n) {
product*=x[i];
product%=m;
}
long long hi=y[n-1];
long long divide=1;
for (int i = n-2; i<=0; i--) {
hi*=x[i+1];
hi=max(hi,y[i]);
divide*=x[i+1];
if (hi>1e9) break;
}
long long ans=hi*product;
ans%=m;
ans*=inverse(divide);
ans%=m;
return ans;
}
int updateY(int pos, int val) {
y[pos]=val;
long long product=1;
rep (i,0,n) {
product*=x[i];
product%=m;
}
long long hi=y[n-1];
long long divide=1;
for (int i = n-2; i<=0; i--) {
hi*=x[i+1];
hi=max(hi,y[i]);
divide*=x[i+1];
if (hi>1e9) break;
}
long long ans=hi*product;
ans%=m;
ans*=inverse(divide);
ans%=m;
return ans;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:40:10: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
if (hi>1e9) break;
^~~
horses.cpp:46:9: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return ans;
^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:64:10: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
if (hi>1e9) break;
^~~
horses.cpp:70:9: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return ans;
^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:86:10: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
if (hi>1e9) break;
^~~
horses.cpp:92:9: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return ans;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
504 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
764 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1530 ms |
14592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
14592 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
14592 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |