#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#define ll long long
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
const int N = 2e5 + 100, mod = 1e9 + 7;
struct Node {
int ans, x, y; // ans is the answer, x is the value of x, y is the value of y
double X, Y, m; // X = sum of logs of X
};
Node tree[N];
int mul(int& a, int b) {
a = (ll)a * b % mod;
return a;
}
void upd(int node, int l, int r, int p, int x, int y) {
if(r < p || l < p) return;
if(l == r) {
if(x) {
tree[node].X = log10(x); tree[node].x = x; tree[node].m = tree[node].X + tree[node].Y;
}
if(y) {
tree[node].Y = log10(y); tree[node].y = y; tree[node].m = tree[node].X + tree[node].Y;
}
tree[node].ans = tree[node].x * tree[node].y;
return;
}
int mid = (l + r) / 2;
upd(node * 2, l, mid, p, x, y);
upd(node * 2 + 1, mid + 1, r, p, x, y);
tree[node].X = tree[node * 2 + 1].X + tree[node * 2].X;
tree[node].x = mul(tree[node * 2 + 1].x, tree[node * 2].x);
// check if the answer is on the left or on the right
if(tree[node * 2].m < tree[node * 2 + 1].m + tree[node * 2].X) {
tree[node].m = tree[node * 2 + 1].m + tree[node * 2].X;
tree[node].ans = mul(tree[node * 2 + 1].ans, tree[node * 2].x);
} else {
tree[node].m = tree[node * 2].m;
tree[node].ans = tree[node * 2].ans;
}
}
int n;
int init(int n_, int x[], int y[]) {
n = n_;
for(int i = 0; i < n; ++i) {
upd(1, 0, n - 1, i, x[i], y[i]);
}
return tree[1].ans;
}
int updateX(int pos, int val) {
upd(1, 0, n - 1, pos, val, 0);
return tree[1].ans;
}
int updateY(int pos, int val) {
upd(1, 0, n - 1, pos, 0, val);
return tree[1].ans;
}
// static char buffer[1024];
// static int currentChar = 0;
// static int charsNumber = 0;
// static inline int read() {
// if (charsNumber < 0) {
// exit(1);
// }
// if (!charsNumber || currentChar == charsNumber) {
// charsNumber = (int)fread(buffer, sizeof(buffer[0]), sizeof(buffer), stdin);
// currentChar = 0;
// }
// if (charsNumber <= 0) {
// return -1;
// }
// return buffer[currentChar++];
// }
// static inline int readInt() {
// int x; cin >> x;
// return x;
// }
// int main() {
// int N;
// N = readInt();
// int *X = (int *)malloc(sizeof(int) * (unsigned int)N);
// int *Y = (int *)malloc(sizeof(int) * (unsigned int)N);
// for (int i = 0; i < N; i++) {
// X[i] = readInt();
// }
// for (int i = 0; i < N; i++) {
// Y[i] = readInt();
// }
// printf("%d\n", init(N, X, Y));
// int M;
// M = readInt();
// for (int i = 0; i < M; i++) {
// int type;
// type = readInt();
// int pos;
// pos = readInt();
// int val;
// val = readInt();
// if (type == 1) {
// printf("%d\n", updateX(pos, val));
// } else if (type == 2) {
// printf("%d\n", updateY(pos, val));
// }
// }
// return 0;
// }
Compilation message
horses.cpp: In function 'int mul(int&, int)':
horses.cpp:31:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
31 | a = (ll)a * b % mod;
| ~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
8276 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |