#include <bits/stdc++.h>
#include "joitour.h"
using namespace std;
using ll = long long;
#define int ll
const int N = 2e5 + 5;
struct node {
int z, u, d, zu, ud, zud;
};
node join (node a, node b) {
node c;
c.z = a.z + b.z;
c.u = a.u + b.u;
c.d = a.d + b.d;
c.zu = a.zu + b.zu + a.z * b.u;
c.ud = a.ud + b.ud + a.u * b.d;
c.zud = a.zud + a.zu * b.d + a.z * b.ud + b.zud;
return c;
}
node aint[4 * N];
int tip[N], n;
void build(int pos, int st, int dr) {
if (st == dr) {
aint[pos] = {0, 0, 0, 0, 0, 0};
if (tip[st] == 0)
aint[pos].z = 1;
else if (tip[st] == 1)
aint[pos].u = 1;
else
aint[pos].d = 1;
return;
}
int mid = (st + dr) / 2;
build (2 * pos, st, mid);
build (2 * pos + 1, mid + 1, dr);
aint[pos] = join(aint[2 * pos], aint[2 * pos + 1]);
}
void update(int pos, int st, int dr, int l, int v) {
if (st == dr) {
aint[pos] = {0, 0, 0, 0, 0, 0};
if (v == 0)
aint[pos].z = 1;
else if (v == 1)
aint[pos].u = 1;
else
aint[pos].d = 1;
return;
}
int mid = (st + dr) / 2;
if (l <= mid)
update(2 * pos, st, mid, l, v);
else
update(2 * pos + 1, mid + 1, dr, l, v);
aint[pos] = join(aint[2 * pos], aint[2 * pos + 1]);
}
void init(signed _N, vector<signed> F, vector<signed> U, vector<signed> V, signed Q) {
n = _N;
for (int i = 0; i < n; i ++)
tip[i] = F[i];
build(1, 0, n - 1);
}
void change(signed x, signed y) {
update(1, 0, n - 1, x, y);
}
int num_tours() {
return aint[1].zud;
}
/*
pentru lant ce pot face
fac pentru de la stanga la dreapta si de la dreapta la stanga separat
am nevoie acum de numarul de 0 - 1 - 2
pot sa fac un aint care suporta urmatoarele operatii:
mentine pe un interval numarul de 0, 1, 2, 0-1, 1-2, 0-1-2
si e doar un mare join
real
*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |