이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
segtree. Each element i stores (X[0]*X[1]*...*X[i]*Y[i])%MOD
*/
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N1)
#define ffj For(j, 0, P)
#define ffa ffi ffj
//#define s <<" "<<
//#define c <<" : "<<
#define w cout
#define e endl
#define pb push_back
#define mp make_pair
#define a first
#define b second
//#define int ll
const ll MAXN = 500000, MOD = 1000000007;
int N1;
ll tree[4*MAXN+1], lazy[4*MAXN+1], xx[MAXN], yy[MAXN];
ll mI(ll x, ll y) { /// call mI(x, MOD-2)
/// x^y
if (y == 0) return 1;
if (y == 1) return x;
ll p = mI(x, y/2);
p = (p*p)%MOD;
if (y%2 == 1) p = (p*x)%MOD;
return p;
}
void push(int x, int L, int R) {
tree[x] *= lazy[x];
tree[x] %= MOD;
if (L != R) {
lazy[x*2] *= lazy[x];
lazy[x*2] %= MOD;
lazy[x*2+1] *= lazy[x];
lazy[x*2+1] %= MOD;
}
lazy[x] = 1;
}
void update(int x, int L, int R, int oL, int oR, ll v) {
push(x, L, R);
if (R < oL || oR < L) return;
if (oL <= L && R <= oR) {
lazy[x] *= v;
lazy[x] %= MOD;
push(x, L, R);
return;
}
update(x*2, L, (L+R)/2, oL, oR, v);
update(x*2+1,(L+R)/2+1,R,oL, oR, v);
tree[x] = max(tree[x*2], tree[x*2+1]);
}
int answer() {
push(1, 0, N1-1);
assert(tree[1] > 0);
return tree[1];
}
int init(int N, int X[], int Y[]) {
N1 = N;
For (i, 0, 4*MAXN+1) tree[i] = lazy[i] = 1;
ffi xx[i] = X[i], yy[i] = Y[i];
ffi update(1, 0, N-1, i, N-1, X[i]), update(1, 0, N-1, i, i, Y[i]);
return answer();
}
int updateX(int pos, int val) {
//w<< pos << " " << val << " " << (mI(xx[pos], MOD-2)*xx[pos])%MOD<<e;
update(1, 0, N1-1, pos, N1-1, mI(xx[pos], MOD-2));
update(1, 0, N1-1, pos, N1-1, val);
xx[pos] = val;
return answer();
}
int updateY(int pos, int val) {
update(1, 0, N1-1, pos, pos, mI(yy[pos], MOD-2));
update(1, 0, N1-1, pos, pos, val);
yy[pos] = val;
return answer();
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'int answer()':
horses.cpp:62:18: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return tree[1];
~~~~~~^
# | 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... |