#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
typedef long long ll;
struct node {
ll val;
int mxi;
bool flag;
};
const int MAXN=5e5+11;
const int MOD=1e9+7;
node seg[MAXN*4];
ll x[MAXN], y[MAXN];
int n;
pair<ll, bool> queryx(int sind, int ini, int fim, int qini, int qfim) {
if(qini>fim||qfim<ini) return { 1, 0 };
if(qini<=ini&&qfim>=fim) return { seg[sind].val, seg[sind].flag };
int m=(ini+fim)/2; int e=sind*2; int d=e+1;
auto aa=queryx(e, ini, m, qini, qfim);
auto bb=queryx(d, m+1, fim, qini, qfim);
ll cc=aa.first; cc*=bb.first;
if(aa.second||bb.second||cc>=MOD) return { cc%MOD, 1 };
return { cc%MOD, 0 };
}
void updateval(int sind, int ini, int fim, int ind, int val) {
if(ind<ini||ind>fim) return;
if(ini==fim) {
seg[sind].mxi=ini;
seg[sind].val=val;
return;
}
int m=(ini+fim)/2; int e=sind*2; int d=e+1;
updateval(e, ini, m, ind, val); updateval(d, m+1, fim, ind, val);
seg[sind].val=seg[e].val*seg[d].val;
seg[sind].flag=seg[sind].val>((ll)MOD);
if(seg[e].flag||seg[d].flag) seg[sind].flag=1;
seg[sind].val%=MOD;
}
void updatemax(int sind, int ini, int fim, int ind) {
if(ind<ini||ind>fim) return;
if(ini==fim) {
seg[sind].mxi=ini;
seg[sind].val=x[ini];
return;
}
int m=(ini+fim)/2; int e=sind*2; int d=e+1;
updatemax(e, ini, m, ind); updatemax(d, m+1, fim, ind);
auto meio=queryx(1, 1, n, seg[e].mxi+1, seg[d].mxi);
ll aa=y[seg[e].mxi]+(y[seg[d].mxi]-1); aa/=y[seg[d].mxi];
if(aa<=meio.first||meio.second) seg[sind].mxi=seg[d].mxi;
else seg[sind].mxi=seg[e].mxi;
}
void build(int sind, int ini, int fim) {
if(ini==fim) {
seg[sind].mxi=ini;
seg[sind].val=x[ini];
seg[sind].flag=0;
return;
}
int m=(ini+fim)/2; int e=sind*2; int d=e+1;
build(e, ini, m); build(d, m+1, fim);
seg[sind].mxi=seg[e].mxi;
seg[sind].val=seg[e].val*seg[d].val;
seg[sind].flag=seg[sind].val>((ll)MOD);
if(seg[e].flag||seg[d].flag) seg[sind].flag=1;
seg[sind].val%=MOD;
}
int updateX(int ind, int val) {
ind++;
x[ind]=val;
updateval(1, 1, n, ind, val);
updatemax(1, 1, n, ind);
int melhor=seg[1].mxi;
auto meio=queryx(1, 1, n, 1, melhor);
ll resp=y[melhor]*meio.first; resp%=MOD;
return resp;
}
int updateY(int ind, int val) {
ind++;
y[ind]=val;
updatemax(1, 1, n, ind);
int melhor=seg[1].mxi;
auto meio=queryx(1, 1, n, 1, melhor);
ll resp=y[melhor]*meio.first; resp%=MOD;
return resp;
}
int init(int c, int a[], int b[]) {
n=c;
for(int i=1; i<=n; i++) {
x[i]=a[i-1];
y[i]=b[i-1];
}
build(1, 1, n);
for(int i=1; i<=n; i++) updatemax(1, 1, n, i);
return updateY(0, y[1]);
}
// int main() {
// int n, q; int a[1000], b[1000];
// scanf("%d %d", &n, &q);
// for(int i=0; i<n; i++) scanf("%d", &a[i]);
// for(int i=0; i<n; i++) scanf("%d", &b[i]);
// printf("%d\n", init(n, a, b));
// while(q--) {
// int a, b, c, resp; scanf("%d %d %d", &c, &a, &b);
// if(c==1) resp=updateX(a, b);
// else resp=updateY(a, b);
// printf("%d\n", resp);
// }
// }
Compilation message
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:84:12: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return resp;
^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:94:12: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return resp;
^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:105:26: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return updateY(0, y[1]);
~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
408 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
9 ms |
384 KB |
Output is correct |
24 |
Correct |
8 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
7 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
256 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
8 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1585 ms |
30684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
640 KB |
Output is correct |
24 |
Correct |
7 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
8 ms |
560 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
7 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
432 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
33 |
Execution timed out |
1555 ms |
32504 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
284 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
300 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
7 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
8 ms |
384 KB |
Output is correct |
33 |
Execution timed out |
1547 ms |
30584 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |