QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#48733 | #4391. Slayers Come | lqhsmash | WA | 137ms | 43464kb | C++20 | 5.4kb | 2022-09-15 13:49:37 | 2022-09-15 13:49:40 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 50;
const int MOD = 998244353;
int T, n, m, a[N], b[N], c[N];
struct node {
int l, r, v, lazy;
node () { l = r = v = -inf; }
}t[N << 2];
struct line { int l, r; } e[N];
bool operator < (line x, line y) {
return x.r < y.r;
}
struct Tree {
node t[N << 2];
#define ls (x << 1)
#define rs (x << 1 | 1)
void pushup (int x) {
t[x].v = min (t[ls].v, t[rs].v);
}
void build (int l, int r, int* a, int x = 1) {
t[x].l = l, t[x].r = r;
if (l == r) {
t[x].v = a[l];
return ;
}
int mid = (l + r) >> 1;
build (l, mid, a, ls), build (mid + 1, r, a, rs);
pushup (x);
}
int ask_R (int l, int r, int v, int x = 1) {
if (l <= t[x].l && t[x].r <= r) {
// cerr << "v = " << t[x].v << endl;
if (t[x].l == t[x].r) return t[x].v >= v ? t[x].r : 0;
if (t[x].v >= v) return t[x].r;
if (t[ls].v >= v) return ask_R (l, r, v, rs);
return ask_R (l, r, v, ls);
}
int mid = (t[x].l + t[x].r) >> 1, res = -1;
if (l <= mid) res = max (res, ask_R (l, r, v, ls));
if (r > mid && res == -1) res = max (res, ask_R (l, r, v, rs));
return res;
}
int ask_L (int l, int r, int v, int x = 1) {
if (l <= t[x].l && t[x].r <= r) {
if (t[x].l == t[x].r) return t[x].v >= v ? t[x].l : inf - 1;
if (t[x].v >= v) return t[x].l;
if (t[rs].v >= v) return ask_L (l, r, v, ls);
return ask_L (l, r, v, rs);
}
int mid = (t[x].l + t[x].r) >> 1, res = inf;
if (l <= mid) res = min (res, ask_L (l, r, v, ls));
if (r > mid && res == inf) res = min (res, ask_L (l, r, v, rs));
return res;
}
void print (int x = 1) {
if (t[x].l == t[x].r) {
cerr << t[x].v << ' ';
return ;
}
print (ls), print (rs);
}
}t1, t2;
void pushup (int x) {
t[x].v = (t[ls].v + t[rs].v) % MOD;
}
void pushdown (int x) {
if (t[x].lazy != 1) {
t[ls].lazy = t[ls].lazy * (ll)t[x].lazy % MOD;
t[rs].lazy = t[rs].lazy * (ll)t[x].lazy % MOD;
t[ls].v = t[ls].v * (ll)t[x].lazy % MOD;
t[rs].v = t[rs].v * (ll)t[x].lazy % MOD;
t[x].lazy = 1;
}
}
void build (int l, int r, int x = 1) {
t[x].l = l, t[x].r = r, t[x].lazy = 1;
if (l == r) {
t[x].v = 0;
return ;
}
int mid = (l + r) >> 1;
build (l, mid, ls), build (mid + 1, r, rs);
pushup (x);
}
void update (int p, int v, int x = 1) {
if (t[x].l == t[x].r) {
t[x].v = (t[x].v + v) % MOD;
return ;
}
pushdown (x);
int mid = (t[x].l + t[x].r) >> 1;
if (p <= mid) update (p, v, ls);
if (p > mid) update (p, v, rs);
pushup (x);
}
void update2 (int l, int r, int x = 1) {
if (l <= t[x].l && t[x].r <= r) {
t[x].v = t[x].v * 2 % MOD;
t[x].lazy = t[x].lazy * 2 % MOD;
return ;
}
pushdown (x);
int mid = (t[x].l + t[x].r) >> 1;
if (l <= mid) update2 (l, r, ls);
if (r > mid) update2 (l, r, rs);
pushup (x);
}
int query (int l, int r, int x = 1) {
if (l <= t[x].l && t[x].r <= r)
return t[x].v;
pushdown (x);
int mid = (t[x].l + t[x].r) >> 1, res = 0;
if (l <= mid) res = (res + query (l, r, ls)) % MOD;
if (r > mid) res = (res + query (l, r, rs)) % MOD;
return res;
}
int main() {
#ifdef LOCAL
clock_t c1 = clock();
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
// =================================================
scanf ("%d", &T);
while (T --) {
scanf ("%d%d", &n, &m);
for (int i = 1; i <= n; i ++)
scanf ("%d%d", &a[i], &b[i]);
for (int i = 2; i <= n; i ++)
c[i] = a[i - 1] - b[i];
t1.build (2, n, c);
// for (int i = 1; i <= n; i ++)
// cerr << c[i] << ' ';
// cerr << endl;
for (int i = 1; i < n; i ++)
c[i] = a[i + 1] - b[i];
t2.build (1, n - 1, c);
// for (int i = 1; i <= n; i ++)
// cerr << c[i] << ' ';
// cerr << endl;
// t1.print ();
// cerr << endl;
// cerr << "res = " << t1.ask_R (3, n, 1) << endl;
for (int i = 1; i <= m; i ++) {
int x, L, R;
scanf ("%d%d%d", &x, &L, &R);
if (x == 1) e[i] = {1, max (x, t1.ask_R (x + 1, n, R))};
else if (x == n) e[i] = {min (x, t2.ask_L (1, x - 1, L)), n};
else e[i] = {min (x, t2.ask_L (1, x - 1, L)), max (x, t1.ask_R (x + 1, n, R))};
// cerr << e[i].l << ' ' << e[i].r << endl;
}
sort (e + 1, e + 1 + m);
build (0, n);
update (0, 1);
for (int i = 1; i <= m; i ++) {
int l = e[i].l, r = e[i].r;
update (r, query (l - 1, r));
if (l - 2 >= 0) update2 (0, l - 2);
}
printf("%d\n", query (n, n));
}
// =================================================
#ifdef LOCAL
cerr << "Time Used = " << clock() - c1 << "ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 137ms
memory: 43464kb
input:
100 94361 94314 33869598 5185471 618720133 505036749 409602893 40833389 73363932 853969687 132417645 381351032 465347847 676007624 210787499 3355224 991034578 503557482 118882583 12886598 821718576 953581962 979222818 458179522 17341621 962353208 11732262 180321038 947467293 869555337 27442910 91111...
output:
0 765548836 0 352014620 245792346 317681874 234056023 251622994 0 0 717797734 0 419924917 267938152 0 69387209 176153299 395885904 0 434882815 919222256 714057465 525834689 627707876 0 682155965 503245988 563898767 738708721 601981094 181859800 0 937409618 416046766 0 430291410 957601467 925964124 0...
result:
wrong answer 1st lines differ - expected: '790989612', found: '0'