이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "horses.h"
#define lson (p<<1)
#define rson (p<<1|1)
#define inf 1000000007
#define mod 1000000007
#define rnd() rand_num()
#define bigrnd() dis(rand_num)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
//#define int long long
using namespace std;
unsigned sed=std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0,inf);
template <typename T> void read(T &x){
x=0;char ch=getchar();int fh=1;
while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
x*=fh;
}
template <typename T> void write(T x) {
if (x<0) x=-x,putchar('-');
if (x>9) write(x/10);
putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
int n;
long long x[500005],y[500005];
long long mx[2000005],tag[2000005];
long long qpow(long long a,long long b)
{
long long res=1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void pushup(int p)
{
mx[p]=max(mx[lson],mx[rson]);
}
void build(int p,int l,int r)
{
if(l==r)
{
mx[p]=1;
tag[p]=1;
return;
}
tag[p]=1;
int mid=l+r>>1;
build(lson,l,mid);
build(rson,mid+1,r);
pushup(p);
}
void pushdown(int p)
{
mx[lson]*=tag[p];
mx[lson]%=mod;
tag[lson]*=tag[p];
tag[lson]%=mod;
mx[rson]*=tag[p];
mx[rson]%=mod;
tag[rson]*=tag[p];
tag[rson]%=mod;
tag[p]=1;
}
void modify(int p,int l,int r,int x,int y,long long k)
{
if(x<=l&&r<=y)
{
mx[p]*=k;
mx[p]%=mod;
tag[p]*=k;
tag[p]%=mod;
return;
}
int mid=l+r>>1;
pushdown(p);
if(x<=mid) modify(lson,l,mid,x,y,k);
if(mid+1<=y) modify(rson,mid+1,r,x,y,k);
pushup(p);
}
int init(int N,int X[],int Y[])
{
n=N;
for(int i=1;i<=n;++i)
{
x[i]=X[i-1];
y[i]=Y[i-1];
}
build(1,1,n);
for(int i=1;i<=n;++i)
{
modify(1,1,n,i,n,x[i]);
modify(1,1,n,i,i,y[i]);
}
return mx[1]%mod;
}
int updateX(int pos,int val)
{
pos++;
modify(1,1,n,pos,n,qpow(x[pos],mod-2));
modify(1,1,n,pos,n,val);
x[pos]=val;
return mx[1]%mod;
}
int updateY(int pos,int val)
{
pos++;
modify(1,1,n,pos,pos,qpow(y[pos],mod-2));
modify(1,1,n,pos,pos,val);
y[pos]=val;
return mx[1]%mod;
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp:13:71: warning: conversion from 'std::chrono::duration<long int, std::ratio<1, 1000000000> >::rep' {aka 'long int'} to 'unsigned int' may change value [-Wconversion]
13 | unsigned sed=std::chrono::system_clock::now().time_since_epoch().count();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:58:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | int mid=l+r>>1;
| ~^~
horses.cpp: In function 'void modify(int, int, int, int, int, long long int)':
horses.cpp:75:41: warning: declaration of 'y' shadows a global declaration [-Wshadow]
75 | void modify(int p,int l,int r,int x,int y,long long k)
| ~~~~^
horses.cpp:32:21: note: shadowed declaration is here
32 | long long x[500005],y[500005];
| ^
horses.cpp:75:35: warning: declaration of 'x' shadows a global declaration [-Wshadow]
75 | void modify(int p,int l,int r,int x,int y,long long k)
| ~~~~^
horses.cpp:32:11: note: shadowed declaration is here
32 | long long x[500005],y[500005];
| ^
horses.cpp:85:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
85 | int mid=l+r>>1;
| ~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:105:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
105 | return mx[1]%mod;
| ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:113:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
113 | return mx[1]%mod;
| ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:121:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
121 | return mx[1]%mod;
| ^
# | 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... |