QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#165778 | #6733. Moniphant Sleep | ucup-team1209 | WA | 1ms | 81812kb | C++14 | 7.4kb | 2023-09-05 21:40:37 | 2023-09-05 22:11:31 |
Judging History
answer
#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int oo = 1e9 + 7;
cs int N = 5e5 + 5;
int n, q;
int fix(int x) {
if(x >= oo - 5) return oo;
return x;
}
struct func {
int v1, p, v2, vi;
func (int v1 = 0, int p = -1, int v2 = -1, int vi = oo)
: v1(v1), p(p), v2(v2), vi(vi) {}
int operator () (cs int &x) {
if(x == oo) return vi;
if(x <= p) return v1;
return fix(v2 + x - p);
}
void fit () {
if(v1 < 0) {
v1 = oo;
}
if(v2 < -1) {
p -= v2 + 1;
v2 = -1;
}
if(vi < 0) {
vi = oo;
}
v1 = fix(v1);
v2 = fix(v2);
vi = fix(vi);
p = fix(p);
}
void trans() {
if(v1 == oo) v1 = 0;
if(vi == oo) vi = 0;
}
};
func operator + (cs func &a, cs func &b) {
if(a.p == oo && b.p == oo)
return func(fix(a.v1 + b.v1), oo, 0, fix(a.vi + b.vi));
if(a.p == oo)
return func(fix(a.v1 + b.v1), b.p, fix(a.v1 + b.v2), fix(a.vi + b.vi));
if(b.p == oo)
return func(fix(a.v1 + b.v1), a.p, fix(a.v2 + b.v1), fix(a.vi + b.vi));
assert(0);
}
func F(func a, func b) {
func c;
if(a.p == oo) {
c = func (a.v1, oo, 0, a(b.vi));
for(int i = 0; i <= 10; i++)
assert(c(i) == a(b(i)));
assert(c(oo) == a(b(oo)));
c.fit();
// cout << "FUHE -------------------- " << endl;
// cout << a.v1 << ' ' << a.p << ' ' << a.v2 << ' ' << a.vi << endl;
// cout << b.v1 << ' ' << b.p << ' ' << b.v2 << ' ' << b.vi << endl;
// cout << c.v1 << ' ' << c.p << ' ' << c.v2 << ' ' << c.vi << endl;
// cout << c(0) << ' ' << a(b(0)) <<endl;
// cout << "______________________________ " << endl;
return c;
}
if(b.p == oo) {
c = func (a(b.v1), oo, 0, a(b.vi));
for(int i = 0; i <= 10; i++)
assert(c(i) == a(b(i)));
assert(c(oo) == a(b(oo)));
c.fit();
// cout << "FUHE -------------------- " << endl;
// cout << a.v1 << ' ' << a.p << ' ' << a.v2 << ' ' << a.vi << endl;
// cout << b.v1 << ' ' << b.p << ' ' << b.v2 << ' ' << b.vi << endl;
// cout << c.v1 << ' ' << c.p << ' ' << c.v2 << ' ' << c.vi << endl;
// cout << c(0) << ' ' << a(b(0)) <<endl;
// cout << "______________________________ " << endl;
return c;
}
c.vi = a(b.vi);
c.p = b.p;
c.v1 = a(b.v1);
if(a.p > b.v2) {
c.p += a.p - b.v2;
c.v1 = a.v1;
}
c.v2 = a(b(c.p + 1)) - 1;
// cout << "FUHE -------------------- " << endl;
// cout << a.v1 << ' ' << a.p << ' ' << a.v2 << ' ' << a.vi << endl;
// cout << b.v1 << ' ' << b.p << ' ' << b.v2 << ' ' << b.vi << endl;
// cout << c.v1 << ' ' << c.p << ' ' << c.v2 << ' ' << c.vi << endl;
// cout << c(0) << ' ' << a(b(0)) <<endl;
// cout << "______________________________ " << endl;
for(int i = 0; i <= 10; i++)
assert(c(i) == a(b(i)));
assert(c(oo) == a(b(oo)));
c.fit();
return c;
}
func flat (func x) {
if(x.v1 == oo) x.v1 = 0;
if(x.vi == oo) x.vi = 0;
return x;
}
struct skip {
func a, c;
int d;
bool add;
skip (func a = func(0, oo, 0, 0), func c = func(0, -1, -1, oo), int d = 0, bool add = 0)
: a(a), c(c), d(d), add(add) {}
void operator += (cs skip &x) {
if(x.add) {
a = a + flat (F(x.a, c));
add = 1;
}
d += x.d;
c = F(x.c, c);
}
};
#define mid ((l + r) >> 1)
skip t[N << 2];
skip a[4] = {
skip(func(0, oo, 0, 0), func(0, -1, 0, oo), 1, 0),
skip(func(0, oo, 0, 0), func(oo, 0, -1, oo), -1, 0),
skip(func(0, oo, 0, 0), func(0, -1, -1, 0), 0, 0),
skip(func(0, -1, -1, 0), func(oo, oo, 0, oo), 0, 1)
};
void pbpb(skip & c, int op) {
c += a[op - 1];
}
void put(int x, skip c) {
t[x] += c;
}
void down(int x) {
put(x << 1, t[x]);
put(x << 1 | 1, t[x]);
t[x] = skip();
}
void modify (int x, int l, int r, int L, int R, int op) {
if(L <= l && r <= R) {
pbpb(t[x], op);
return;
}
down(x);
if(L <= mid) modify(x << 1, l, mid, L, R, op);
if(R > mid) modify(x << 1 | 1, mid + 1, r, L, R, op);
}
int query(int x, int l, int r, int p) {
if(l == r) {
return t[x].d - t[x].a(oo);
}
down(x);
if(p <= mid) return query(x << 1, l, mid, p);
return query(x << 1 | 1, mid + 1, r, p);
}
// void dfs(int u, int l, int r) {
// if(l == r) return;
// down(u);
// dfs(u << 1, l, mid);
// dfs(u<< 1 | 1, mid + 1, r);
// }
#undef mid
int main() {
#ifdef zqj
freopen("1.in","r",stdin);
#endif
cin >> n >> q;
// unsigned seed = 1693905673u;// time(0);
// srand(seed);
// cerr << seed << endl;
vector <int> at(5);
for(int i=0; i<at.size(); i++) at[i]=rand()%4;
// cout << a1.c.v1 << ' ' << a1.c.v2 << ' ' << a1.c.vi << ' ' << a1.c.p << endl;
// cout << a1.a.v1 << ' ' << a1.a.v2 << ' ' << a1.a.vi << ' ' << a1.a.p << endl;
// a1 = a[3], a2 = a[2], a3 = a[0];;
// a2 += a3;
// a1 += a2;
// cout << a1.c.v1 << ' ' << a1.c.v2 << ' ' << a1.c.vi << ' ' << a1.c.p << endl;
// cout << a1.a.v1 << ' ' << a1.a.v2 << ' ' << a1.a.vi << ' ' << a1.a.p << endl;
// a1 += skip();
// cout << a1.a.v1 << ' ' << a1.a.p << ' ' << a1.a.v2 << ' ' << a1.a.vi << endl;
// skip c;
// c += a1;
// a1 = c;
// cout << a1.a.v1 << ' ' << a1.a.p << ' ' << a1.a.v2 << ' ' << a1.a.vi << endl;
skip fr, bk;
at = {2, 1, 3};
for(int i=0; i< at.size(); i++) {
fr+=a[at[i]];
cout << fr.c.v1 << ' ' << fr.c.p << ' ' << fr.c.v2 << ' ' << fr.c.vi << endl;
cout << fr.a.v1 << ' ' << fr.a.p << ' ' << fr.a.v2 << ' ' << fr.a.vi << endl;
}
cout << endl;
for(int i=at.size()-1; ~i; i--){
skip tmp=a[at[i]];
tmp+=bk;
bk=tmp;
cout << bk.c.v1 << ' ' << bk.c.p << ' ' << bk.c.v2 << ' ' << bk.c.vi << endl;
cout << bk.a.v1 << ' ' << bk.a.p << ' ' << bk.a.v2 << ' ' << bk.a.vi << endl;
}
for(int x: at) cout << x << ' '; cout << endl;
assert(bk.c.v1==fr.c.v1);
assert(bk.c.v2==fr.c.v2);
assert(bk.c.vi==fr.c.vi);
assert(bk.c.p==fr.c.p);
assert(bk.a.v1==fr.a.v1);
assert(bk.a.v2==fr.a.v2);
assert(bk.a.vi==fr.a.vi);
assert(bk.a.p==fr.a.p);
// return 0
for(int z = 0; z < q; z++) {
int op, l, r;
scanf("%d%d%d", &op, &l, &r);
// if(op <= 4) {
// modify(1, 1, n, l, r, op);
// }
// if(op == 5) {
// cout << query(1, 1, n, l) + 500000 << '\n';
// }
if(op <= 4) {
for(int i = l; i <= r; i++)
pbpb(t[i], op);
}
if(op == 5) {
cout << t[l].d - t[l].a(oo) + 500000 << '\n';
}
// cout << "FF " << l << ' ' << r << ' ' << op<< endl;
// for(int j = 4; j <= 4; j++) {
// cout << t[j].c.v1 << ' ' << t[j].c.p << ' ' << t[j].c.v2 << ' ' << t[j].c.vi << '\n';
// cout << t[j].a.v1 << ' ' << t[j].a.p << ' ' << t[j].a.v2 << ' ' << t[j].a.vi << '\n';
// cout << t[j].d << ' ' << t[j].d - t[j].a(oo) << endl;
// }
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 81812kb
input:
1 9 1 1 1 1 1 1 1 1 1 3 1 1 2 1 1 1 1 1 1 1 1 4 1 1 5 1 1
output:
0 -1 -1 0 0 1000000007 0 0 1000000007 0 -1 1000000007 0 1000000007 0 0 1000000007 1000000007 0 1000000007 0 0 -1 0 1000000007 1000000007 0 1000000007 0 -1 -1 0 1000000007 1000000007 0 1000000007 0 0 -1 0 1000000007 1000000007 0 1000000007 0 0 -1 0 2 1 3 500004
result:
wrong answer 1st numbers differ - expected: '500004', found: '0'