이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=1000000000+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+m;
}
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>1000000000) 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>1000000000) 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>1000000000) break;
}
long long ans=hi*product;
ans%=m;
ans*=inverse(divide);
ans%=m;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:44: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:68: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:90:9: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return ans;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |