QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#387937 | #4879. Standard Problem | Giga_Cronos# | WA | 0ms | 3692kb | C++23 | 4.3kb | 2024-04-13 05:39:36 | 2024-04-13 05:39:36 |
Judging History
answer
#include <bits/stdc++.h>
typedef long double ld;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, pii> pip;
typedef pair<ld, int> pdi;
const ll mod = 998244353;
struct ST {
vector<pii> st;
vector<int> lazy;
int n;
ST(int _n) {
n = _n;
st.resize(4 * n);
lazy.resize(4 * n);
}
pii merge(pii a, pii b) {
if (a.first == b.first)
return pii(a.first, (a.second + b.second) % mod);
if (a.first > b.first)
return a;
return b;
}
void up(int p, ll x) {
st[p].first += x;
lazy[p] += x;
}
void push(int p, int l, int r) {
if (!lazy[p])
return;
if (l == r) {
lazy[p] = 0;
return;
}
up(p << 1, lazy[p]);
up((p << 1) + 1, lazy[p]);
lazy[p] = 0;
}
void build(vector<pii> &x) { build(1, 0, n - 1, x); }
void build(int p, int l, int r, vector<pii> &x) {
if (l == r) {
st[p] = x[l];
return;
}
int mid = (l + r) / 2;
build(p << 1, l, mid, x);
build((p << 1) + 1, mid + 1, r, x);
st[p] = merge(st[p << 1], st[(p << 1) + 1]);
}
pii query(int L, int R) { return query(1, 0, n - 1, L, R); }
pii query(int p, int l, int r, int L, int R) {
push(p, l, r);
if (L <= l && r <= R) {
// cout << l << ' ' << r << "\n";
// cout << L << ' ' << R << "\n";
// cout << p << ' ' << st[p].first << ' ' << st[p].second << "\n";
return st[p];
}
int mid = (l + r) / 2;
if (R <= mid) {
auto x = query(p << 1, l, mid, L, R);
// cout << p << ' ' << x.first << ' ' << x.second << "\n";
return x;
}
if (L > mid)
return query((p << 1) + 1, mid + 1, r, L, R);
// cout << "xxx" << ' ' << p << ' ' << l << ' ' << r << "\n";
return merge(query(p << 1, l, mid, L, R),
query((p << 1) + 1, mid + 1, r, L, R));
}
void set(int pos, pii v) { set(1, 0, n - 1, pos, v); }
void set(int p, int l, int r, int pos, pii v) {
push(p, l, r);
if (l == r) {
st[p] = v;
// cout << p << ' ' << st[p].first << ' ' << st[p].second << "\n";
return;
}
int mid = (l + r) / 2;
if (pos <= mid)
set(p << 1, l, mid, pos, v);
if (pos > mid)
set((p << 1) + 1, mid + 1, r, pos, v);
st[p] = merge(st[p << 1], st[(p << 1) + 1]);
// cout << p << ' ' << st[p].first << ' ' << st[p].second << "\n";
}
void update(int L, int R, ll v) { update(1, 0, n - 1, L, R, v); }
void update(int p, int l, int r, int L, int R, ll v) {
push(p, l, r);
if (L <= l && r <= R) {
up(p, v);
return;
}
int mid = (l + r) / 2;
if (L <= mid)
update(p << 1, l, mid, L, R, v);
if (R > mid)
update((p << 1) + 1, mid + 1, r, L, R, v);
st[p] = merge(st[p << 1], st[(p << 1) + 1]);
}
};
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// int n;
// int _w;
// cin >> n >> _w;
// ld w = _w;
// priority_queue<pdi, vector<pdi>, greater<pdi>> pq;
// vector<pii> vp;
// for (int i = 0; i < n; i++) {
// int t, s, p;
// cin >> t >> s >> p;
// vp.push_back(pii(s, p));
// pq.push(pdi(t, i + 1));
// }
// while(!pq.empty())
// {
// }
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
ST st(m + 1);
vector<pii> base(m + 1);
for (int i = 0; i <= m; i++)
base[i] = pii(-1e18, 0);
base[0] = pii(0, 1);
st.build(base);
set<int> vals_d;
vals_d.insert(0);
auto app = [&](int l, int r, int w) {
pii q = st.query(0, l);
// cout << q.first << ' ' << q.second << "\n";
q.first += w;
vals_d.insert(l);
// cout << q.first << ' ' << q.second << "\n";
st.set(l, q);
st.update(l + 1, r, w);
auto it = vals_d.lower_bound(r + 1);
if (it == vals_d.end())
return;
it--;
ll ma = st.query(*it, *it).first;
it++;
vector<int> to_er;
while (it != vals_d.end()) {
pii x = st.query(*it, *it);
if (x.first >= ma)
break;
to_er.push_back(*it);
it++;
}
for (auto x : to_er) {
st.set(x, pii(-1e18, 0));
vals_d.erase(x);
}
};
for (int i = 0; i < n; i++) {
int l, r, w;
cin >> l >> r >> w;
app(l, r, w);
// cout << "\n";
// cout << i << "\n";
// for (int j = 0; j <= m; j++) {
// auto p = st.query(j, j);
// cout << j << ' ' << p.first << ' ' << p.second << "\n";
// }
}
pii x = st.query(0, m);
cout << x.first << ' ' << x.second << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
2 3 4 1 2 1 2 3 1 2 2 1 2 5 1 4 3 2 5 3
output:
3 1 6 1
result:
ok 4 number(s): "3 1 6 1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3692kb
input:
30 3 3 1 3 1 1 3 1 1 3 1 3 3 1 2 1 1 3 1 1 3 1 3 3 2 2 1 1 3 1 1 3 1 3 3 1 3 1 1 2 1 1 3 1 3 3 2 3 1 1 2 1 1 3 1 3 3 2 2 1 1 3 1 1 3 1 3 3 2 2 1 1 2 1 1 3 1 3 3 1 3 1 2 3 1 1 3 1 3 3 2 3 1 1 3 1 2 2 1 3 3 1 2 1 1 2 1 1 2 1 3 3 1 3 1 1 3 1 1 3 1 3 3 1 3 1 1 2 1 1 3 1 3 3 2 3 1 1 2 1 1 3 1 3 3 1 3 1 1...
output:
3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 2 2 3 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1
result:
wrong answer 33rd numbers differ - expected: '3', found: '2'